Py学习  »  Redis

如何在redis golang中将键值对传递给MSet?

Sukeesh • 5 年前 • 1043 次点击  

pairs ...interface{} here

func (c *cmdable) MSet(pairs ...interface{}) *StatusCmd {
    args := make([]interface{}, 1, 1+len(pairs))
    args[0] = "mset"
    args = appendArgs(args, pairs)
    cmd := NewStatusCmd(args...)
    c.process(cmd)
    return cmd
}

现在,我有了 keys []string 映射到 values []int64 在Redis缓存中设置。如何将它们转换为接口片段并将它们传递给 MSet

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/57110
 
1043 次点击  
文章 [ 1 ]  |  最新文章 5 年前
Cerise Limón
Reply   •   1 楼
Cerise Limón    6 年前

使用for循环将键和值复制到切片:

var pairs []interface{}
for i := range keys {
  pairs = append(pairs, keys[i], values[i])
}
cmd := c.MSet(pairs...)