Skip to content
Gary Burd edited this page Oct 7, 2013 · 15 revisions

How do I call a command with a variable number of arguments?

The args parameter to the connection Send and Do methods is variadic. Use the ... notation to pass a slice to a variadic argument.

// Set multiple HASH fields using values in map fvs.
var args []interface{"key"}
for f, v := range fvs {
    args = append(args, f, v)
}
_, err := conn.Do("HMSET", args...)

If you have a slice that's not of type []interface{}, then copy the values to a []interface{} before calling the Send or Do method.

Redigo's Args type can be used to construct variable length argument lists.

How do I call a command with a space in the name?

Some Redis command names contain a space. Use the full name with the space as the first argument to the connection Send and Do methods:

_, err := conn.Do("CONFIG SET", "loglevel", "warning")
Clone this wiki locally