MSet in redis-go accepts 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...)
    return cmd

Now, I have keys []string mapped to values []int64 to be set in Redis cache. How do I convert them to slice of interfaces and pass them to MSet to make it work?

1 Answers

ThunderCat On Best Solutions

Use a for loop to copy the keys and values to a slice:

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