Skip to content
Steven Hartland edited this page Sep 14, 2022 · 15 revisions

Is Redigo thread-safe?

See https://godoc.org/github.com/gomodule/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 fields in HASH "myhash" using values from map fvs.
var args = []interface{}{"myhash"}
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. Split the name on space. Pass the first part as the command name and the remaining parts as arguments:

_, 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.