douzi1350 2017-10-10 09:04
浏览 90
已采纳

Aerospike Golang ListInsertOp多个值

Does the ListInsertOp in golang aerospike client support inserting an array of elements ?

If I use https://godoc.org/github.com/aerospike/aerospike-client-go#ListAppendOp, and pass an array ([]string), it just appends the whole array as one value in the list. Am I using it wrong or is there another way to do the same?

  • 写回答

1条回答 默认 最新

  • dongyu3967 2017-10-10 11:04
    关注

    ListAppendOp is a variadic function accepting arbitrary number of arguments of type interface{}. If you call it passing your array, it will receive a slice of interface{} ([]interface{}) with a single element which is your array.

    You need to convert your array to a slice of interface{} and expand it using ... when passing it to the function:

    a := []string{"a", "b", "c"}
    
    s := make([]interface{}, len(a))
    for i, v := range a {
      s[i] = v
    }
    
    ListAppendOp("bin1", s...)
    

    Example of passing an array to a variadic function: https://play.golang.org/p/541aJ6dY6D

    From the specs: Passing arguments to ... parameters

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 关于无人驾驶的航向角
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了