一個基於golang的redis cluster 客戶端
阿新 • • 發佈:2018-12-25
用法
引入並建立叢集
import "github.com/gitstliu/go-redis-cluster"
cluster, err := redis.NewCluster(
&redis.Options{
StartNodes: []string{"127.0.0.1:7000", "127.0.0.1:7001", "127.0.0.1:7002"},
ConnTimeout: 50 * time.Millisecond,
ReadTimeout: 50 * time.Millisecond,
WriteTimeout: 50 * time.Millisecond,
KeepAlive: 16 ,
AliveTime: 60 * time.Second,
})
執行一些命令
cluster.Do("SET", "foo", "bar")
cluster.Do("INCR", "mycount", 1)
cluster.Do("LPUSH", "mylist", "foo", "bar")
cluster.Do("HMSET", "myhash", "f1", "foo", "f2", "bar")