Skip to content
Gary Burd edited this page Apr 1, 2014 · 15 revisions

Is Redigo thread-safe?

See http://godoc.org/github.com/garyburd/redigo/redis#hdr-Concurrency.

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")

Does Redigo provide a way to serialize structs to Redis?

No. The application can easily serialize structs using encoding/gob, encoding/json or other packages.

The Args AddFlat method and the ScanStruct function are provided to simplify code for building command argument lists and parsing command responses. These functions are not intended to be used as a tool for serializing structs to Redis.

Does the Redigo pool support blocking get and other advanced features in Vitess pools?

No, but the application can use Vitess pools with Redigo. See Vitess-Example for a brief example of how to use a Vitess pool with Redigo.

Clone this wiki locally