-
Notifications
You must be signed in to change notification settings - Fork 13
Connection and Command
Tam. Nguyen Duc edited this page May 30, 2014
·
2 revisions
Gore only supports TCP connection for Redis. The connection is thread-safe and can be auto-repaired with or without sentinel.
conn, err := gore.Dial("localhost:6379")
if err != nil {
return
}
defer conn.Close()
Redis command is built with NewCommand
gore.NewCommand("SET", "kirisame", "marisa") // SET kirisame marisa
gore.NewCommand("ZADD", "magician", 1337, "alice") // ZADD magician 1337 alice
gore.NewCommand("HSET", "sdm", "sakuya", 99) // HSET smd sakuya 99
In the last command, the value stored by redis will be the string "99", not the integer 99.
- Integer and float values are converted to string using strconv
- Boolean values are convert to "1" and "0"
- Nil values are stored as zero length string
- Other types are converted to string using standard fmt.Sprint
To efficiently store integer, you can use gore.FixInt or gore.VarInt
Gore supports compacting integer to reduce memory used by redis. There are 2 ways of compacting integer:
- gore.FixInt stores an integer as a fixed 8 bytes []byte.
- gore.VarInt encodes an integer with variable length []byte.
gore.NewCommand("SET", "fixint", gore.FixInt(1337)) // Set fixint as an 8 bytes []byte
gore.NewCommand("SET", "varint", gore.VarInt(1337)) // varint only takes 3 bytes