在实际go语言开发中经常会用到Redis分布式缓存,而苦于没有一个好的第三方工具包,现在分享下实际项目使用基于分布式缓存Codis时编写的Redis工具类。
完整代码:https://github.com/dunzung/godis
定义RoundRobinPool 的Codis连接池类
package godisimport ("encoding/json""fmt""github.com/go-redis/redis""github.com/pkg/errors""github.com/samuel/go-zookeeper/zk""log""sort""sync/atomic")type ZKProxyInfo struct {Addr string `json:"addr"`State string `json:"state"`}type PooledObject struct {Addr stringClient *redis.Client}type RoundRobinPool struct {zkConn *zk.ConnzkProxyDir stringpools atomic.ValuechildCh