X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=internal%2Fsdlgoredis%2Fsdlgoredis.go;h=8e2a2ef2e12e265dfce2b6f17a3adab5cfacc9b1;hb=f759492b4f02f1e9d66115a6b83deec519cb5df4;hp=0ccccb6258f79e52db5121cfacf625a6d6f95f1d;hpb=a10caff26de79e06caac2d00d3c11218e2d7ee87;p=ric-plt%2Fsdlgo.git diff --git a/internal/sdlgoredis/sdlgoredis.go b/internal/sdlgoredis/sdlgoredis.go index 0ccccb6..8e2a2ef 100644 --- a/internal/sdlgoredis/sdlgoredis.go +++ b/internal/sdlgoredis/sdlgoredis.go @@ -92,7 +92,7 @@ func checkIntResultAndError(result interface{}, err error) (bool, error) { if err != nil { return false, err } - if result == 1 { + if result.(int64) == int64(1) { return true, nil } return false, nil @@ -119,6 +119,7 @@ func CreateDB(client RedisClient, subscribe SubscribeFn) *DB { } func Create() *DB { + var client *redis.Client hostname := os.Getenv("DBAAS_SERVICE_HOST") if hostname == "" { hostname = "localhost" @@ -127,13 +128,26 @@ func Create() *DB { if port == "" { port = "6379" } - redisAddress := hostname + ":" + port - client := redis.NewClient(&redis.Options{ - Addr: redisAddress, - Password: "", // no password set - DB: 0, // use default DB - PoolSize: 20, - }) + sentinelPort := os.Getenv("DBAAS_SERVICE_SENTINEL_PORT") + masterName := os.Getenv("DBAAS_MASTER_NAME") + if sentinelPort == "" { + redisAddress := hostname + ":" + port + client = redis.NewClient(&redis.Options{ + Addr: redisAddress, + Password: "", // no password set + DB: 0, // use default DB + PoolSize: 20, + MaxRetries: 2, + }) + } else { + sentinelAddress := hostname + ":" + sentinelPort + client = redis.NewFailoverClient(&redis.FailoverOptions{ + MasterName: masterName, + SentinelAddrs: []string{sentinelAddress}, + PoolSize: 20, + MaxRetries: 2, + }) + } db := CreateDB(client, subscribeNotifications) db.CheckCommands() return db @@ -169,7 +183,7 @@ func (db *DB) UnsubscribeChannelDB(channels ...string) { } } -func (db *DB) SubscribeChannelDB(cb ChannelNotificationCb, channelPrefix, eventSeparator string, channels ...string) { +func (db *DB) SubscribeChannelDB(cb func(string, ...string), channelPrefix, eventSeparator string, channels ...string) { if len(db.cbMap) == 0 { for _, v := range channels { db.cbMap[v] = cb