doww38701 2017-07-24 10:58
浏览 39
已采纳

通话中的参数过多

I'm trying to load db data to redis cluster using mysql2redis.

When i try the accepted solution, i.e.,

} else if e.Command == "HMSET" {
    // Build up a string slice to hold the key value pairs
    args := make([]string, 0, len(e.MapData) * 2)
    for k, v := range e.MapData {
        args = append(args, k, v)
    }
    _,err := redis.StringMap(client.Do("HMSET", e.Key, args...))
    checkErr(err, "hmset error:")
}

I get following exception,

too many arguments in call to client.Do
    have (string, string, []string...)
    want (string, ...interface {})

I'm a newbie when it comes to Go. So can the Go veterans take a look at this and suggest a solution?

  • 写回答

1条回答 默认 最新

  • dongzhangnong2063 2017-07-24 11:16
    关注

    In Go you can use a slice for a variadic parameter. However, the slice must contain all the parameters you need to pass to the function. You cannot expand a slice and pass additional parameters as well.

    Hence your code should be something like:

    args := make([]interface{}, 0, len(e.MapData) * 2 + 1)
    args = append(args, e.Key)
    for k, v := range e.MapData {
        args = append(args, k, v)
    }
    _,err := redis.StringMap(client.Do("HMSET", args...))
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题