+ return checkIntResultAndError(db.client.Do("DELIE", key, data).Result())
+}
+
+func (db *DB) SAdd(key string, data ...interface{}) error {
+ _, err := db.client.SAdd(key, data...).Result()
+ return err
+}
+
+func (db *DB) SRem(key string, data ...interface{}) error {
+ _, err := db.client.SRem(key, data...).Result()
+ return err
+}
+
+func (db *DB) SMembers(key string) ([]string, error) {
+ result, err := db.client.SMembers(key).Result()
+ return result, err
+}
+
+func (db *DB) SIsMember(key string, data interface{}) (bool, error) {
+ result, err := db.client.SIsMember(key, data).Result()
+ return result, err
+}
+
+func (db *DB) SCard(key string) (int64, error) {
+ result, err := db.client.SCard(key).Result()
+ return result, err
+}
+
+func (db *DB) PTTL(key string) (time.Duration, error) {
+ result, err := db.client.PTTL(key).Result()
+ return result, err
+}
+
+func (db *DB) Info() (*DbInfo, error) {
+ var info DbInfo
+ resultStr, err := db.client.Info("all").Result()
+ if err != nil {
+ return &info, err
+ }
+
+ result := strings.Split(strings.ReplaceAll(resultStr, "\r\n", "\n"), "\n")
+ err = readRedisInfoReplyFields(result, &info)
+ return &info, err
+}
+
+func readRedisInfoReplyFields(input []string, info *DbInfo) error {
+ for _, line := range input {
+ if idx := strings.Index(line, "role:"); idx != -1 {
+ roleStr := line[idx+len("role:"):]
+ if roleStr == "master" {
+ info.Fields.PrimaryRole = true
+ }
+ } else if idx := strings.Index(line, "connected_slaves:"); idx != -1 {
+ cntStr := line[idx+len("connected_slaves:"):]
+ cnt, err := strconv.ParseUint(cntStr, 10, 32)
+ if err != nil {
+ return fmt.Errorf("Info reply error: %s", err.Error())
+ }
+ info.Fields.ConnectedReplicaCnt = uint32(cnt)
+ }
+ }
+ return nil
+}
+
+func (db *DB) State() (*DbState, error) {
+ dbState := new(DbState)
+ if db.cfg.sentinelPort != "" {
+ //Establish connection to Redis sentinel. The reason why connection is done
+ //here instead of time of the SDL instance creation is that for the time being
+ //sentinel connection is needed only here to get state information and
+ //state information is needed only by 'sdlcli' hence it is not time critical
+ //and also we want to avoid opening unnecessary TCP connections towards Redis
+ //sentinel for every SDL instance. Now it is done only when 'sdlcli' is used.
+ sentinelClient := db.sentinel(&db.cfg, db.addr)
+ return sentinelClient.GetDbState()
+ } else {
+ info, err := db.Info()
+ if err != nil {
+ dbState.PrimaryDbState.Err = err
+ return dbState, err
+ }
+ return db.fillDbStateFromDbInfo(info)
+ }
+}
+
+func (db *DB) fillDbStateFromDbInfo(info *DbInfo) (*DbState, error) {
+ var dbState DbState
+ if info.Fields.PrimaryRole == true {
+ dbState = DbState{
+ PrimaryDbState: PrimaryDbState{
+ Fields: PrimaryDbStateFields{
+ Role: "master",
+ Flags: "master",
+ },
+ },
+ }
+ }
+
+ cnt, err := strconv.Atoi(db.cfg.nodeCnt)