简单实现redis工厂,根据配置动态获取单机实例化对象或集群实例化对象

Golang示例代码

package xxx

type BaseRedis struct {
    Obj interface{}
}

func (this *BaseRedis)instance() (redis.Client, error){}
func (this *BaseRedis)clusterInstance() (redis.ClusterClient, error){}

func Factory() *BaseRedis {
    obj := new(BaseRedis)

    if 单机配置 {
        obj.Obj, err := obj.instance()
    } else {
        obj.Obj, err := obj.clusterInstance()
    }

    return obj
}
//使用(根据配置动态获取实例)
func demo() {
    instance := xxx.Factory()

    instance.Obj.Get("xx") //调用redis.Client.Get 或 redis.ClusterClient.Get方法?
}