limitations under the License.
*/
+/*
+ * This source code is part of the near-RT RIC (RAN Intelligent Controller)
+ * platform project (RICP).
+ */
+
package sdlgoredis
import (
if err != nil {
return false, err
}
- if result == 1 {
+ if result.(int) == int(1) {
return true, nil
}
return false, nil
}
func Create() *DB {
+ var client *redis.Client
hostname := os.Getenv("DBAAS_SERVICE_HOST")
if hostname == "" {
hostname = "localhost"
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
}
}
-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