go-redis-client 是国内团队灵雀云开发的 Go 语言的 Redis 客户端开发包,支持 Redis 单机和集群。
package main import "redis" github.com/alauda/go-redis-client func main() { // check options.go for more details opts := redis.RedisClientOptions{ Type: redis.ClientNormal, Hosts: []string{"localhost:6379"}, Password: "123456", Database: 0, } client := redis.NewRedisClient(opts) if err := client.Ping().Err(); err != nil { panic(err) } // Using cluster mode clusterOpts := redis.RedisClientOptions{ Type: redis.ClientCluster, Hosts: []string{"localhost:7000","localhost:7001","localhost:7002"}, Password: "123456", Database: 0, // all keys with a prefix KeyPrefix: "my-app:", } clusterClient := redis.NewRedisClient(clusterOpts) if err := clusterClient.Ping().Err(); err != nil { panic(err) } }