+ cbMap map[string]ChannelNotificationCb
+ ch intChannels
+}
+
+type Subscriber interface {
+ Channel() <-chan *redis.Message
+ Subscribe(channels ...string) error
+ Unsubscribe(channels ...string) error
+ Close() error
+}
+
+type SubscribeFn func(client RedisClient, channels ...string) Subscriber
+
+type RedisClient interface {
+ Command() *redis.CommandsInfoCmd
+ Close() error
+ Subscribe(channels ...string) *redis.PubSub
+ MSet(pairs ...interface{}) *redis.StatusCmd
+ Do(args ...interface{}) *redis.Cmd
+ MGet(keys ...string) *redis.SliceCmd
+ Del(keys ...string) *redis.IntCmd
+ Keys(pattern string) *redis.StringSliceCmd
+ SetNX(key string, value interface{}, expiration time.Duration) *redis.BoolCmd
+ SAdd(key string, members ...interface{}) *redis.IntCmd
+ SRem(key string, members ...interface{}) *redis.IntCmd
+ SMembers(key string) *redis.StringSliceCmd
+ SIsMember(key string, member interface{}) *redis.BoolCmd
+ SCard(key string) *redis.IntCmd
+ PTTL(key string) *redis.DurationCmd
+ Eval(script string, keys []string, args ...interface{}) *redis.Cmd
+ EvalSha(sha1 string, keys []string, args ...interface{}) *redis.Cmd
+ ScriptExists(scripts ...string) *redis.BoolSliceCmd
+ ScriptLoad(script string) *redis.StringCmd
+}
+
+func checkResultAndError(result interface{}, err error) (bool, error) {
+ if err != nil {
+ if err == redis.Nil {
+ return false, nil
+ }
+ return false, err
+ }
+ if result == "OK" {
+ return true, nil
+ }
+ return false, nil
+}
+
+func checkIntResultAndError(result interface{}, err error) (bool, error) {
+ if err != nil {
+ return false, err
+ }
+ if result.(int64) == int64(1) {
+ return true, nil
+ }
+ return false, nil
+}
+
+func subscribeNotifications(client RedisClient, channels ...string) Subscriber {
+ return client.Subscribe(channels...)
+}
+
+func CreateDB(client RedisClient, subscribe SubscribeFn) *DB {
+ db := DB{
+ client: client,
+ subscribe: subscribe,
+ redisModules: true,
+ cbMap: make(map[string]ChannelNotificationCb, 0),
+ ch: intChannels{
+ addChannel: make(chan string),
+ removeChannel: make(chan string),
+ exit: make(chan bool),
+ },
+ }
+
+ return &db