X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=internal%2Fsdlgoredis%2Fsdlgoredis.go;h=574e7b0a601a9c9b8513a64c56de14fa8c947b84;hb=e135f9ad805819830d55dbeb0566a19d2804df34;hp=56ebfa896641819b86c44f5dcc308d4d0b5695bc;hpb=d64c510705ac1623c052aedc4ddc50aabeb1e798;p=ric-plt%2Fsdlgo.git diff --git a/internal/sdlgoredis/sdlgoredis.go b/internal/sdlgoredis/sdlgoredis.go index 56ebfa8..574e7b0 100644 --- a/internal/sdlgoredis/sdlgoredis.go +++ b/internal/sdlgoredis/sdlgoredis.go @@ -15,6 +15,11 @@ limitations under the License. */ +/* + * This source code is part of the near-RT RIC (RAN Intelligent Controller) + * platform project (RICP). + */ + package sdlgoredis import ( @@ -92,7 +97,7 @@ func checkIntResultAndError(result interface{}, err error) (bool, error) { if err != nil { return false, err } - if result == 1 { + if result.(int) == int(1) { return true, nil } return false, nil @@ -119,6 +124,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,14 +133,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, - MaxRetries: 2, - }) + 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 @@ -170,7 +188,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