diff --git a/README.md b/README.md index 2879068..a63af6c 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ import ( "github.com/go-redis/redis" "github.com/sivaosorg/govm/logger" "github.com/sivaosorg/govm/redisx" - "github.com/sivaosorg/redisconn/redisconn" + "github.com/sivaosorg/redisconn" ) func main() { @@ -75,7 +75,7 @@ import ( "github.com/go-redis/redis" "github.com/sivaosorg/govm/logger" "github.com/sivaosorg/govm/redisx" - "github.com/sivaosorg/redisconn/redisconn" + "github.com/sivaosorg/redisconn" ) func main() { diff --git a/redisconn/redisconn.go b/redisconn.go similarity index 85% rename from redisconn/redisconn.go rename to redisconn.go index ff72f23..38640eb 100644 --- a/redisconn/redisconn.go +++ b/redisconn.go @@ -12,8 +12,7 @@ import ( ) var ( - instance *Redis - _logger = logger.NewLogger() + _logger = logger.NewLogger() ) func NewRedis() *Redis { @@ -44,16 +43,12 @@ func (r *Redis) GetConn() *redis.Client { } func NewClient(config redisx.RedisConfig) (*Redis, dbx.Dbx) { + instance := NewRedis() s := dbx.NewDbx().SetDatabase(config.Database) if !config.IsEnabled { s.SetConnected(false). SetMessage("Redis unavailable"). SetError(fmt.Errorf(s.Message)) - instance = NewRedis().SetState(*s) - return instance, *s - } - if instance != nil { - s.SetConnected(true).SetNewInstance(false) instance.SetState(*s) return instance, *s } @@ -66,7 +61,7 @@ func NewClient(config redisx.RedisConfig) (*Redis, dbx.Dbx) { err := client.Ping().Err() if err != nil { s.SetConnected(false).SetError(err).SetMessage(err.Error()) - instance = NewRedis().SetState(*s) + instance.SetState(*s) return instance, *s } if config.DebugMode { @@ -74,6 +69,6 @@ func NewClient(config redisx.RedisConfig) (*Redis, dbx.Dbx) { _logger.Info(fmt.Sprintf("Connected successfully to redis cache:: %s/%s", config.UrlConn, config.Database)) } s.SetConnected(true).SetMessage("Connected successfully").SetPid(os.Getpid()).SetNewInstance(true) - instance = NewRedis().SetConn(client).SetState(*s) + instance.SetConn(client).SetState(*s) return instance, *s } diff --git a/redisconn/redisconn_config.go b/redisconn_config.go similarity index 100% rename from redisconn/redisconn_config.go rename to redisconn_config.go diff --git a/redisconn/redisconn_model.go b/redisconn_model.go similarity index 100% rename from redisconn/redisconn_model.go rename to redisconn_model.go diff --git a/redisconn/redisconn_pubsub.go b/redisconn_pubsub.go similarity index 100% rename from redisconn/redisconn_pubsub.go rename to redisconn_pubsub.go diff --git a/redisconn/redisconn_service.go b/redisconn_service.go similarity index 100% rename from redisconn/redisconn_service.go rename to redisconn_service.go