From 5a5ef2c3d895f19cbdba1cc29201042d70d9a6ef Mon Sep 17 00:00:00 2001 From: Noah Hilverling Date: Wed, 6 Mar 2019 16:29:18 +0100 Subject: [PATCH] Redis: Add HKeys() --- redis.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/redis.go b/redis.go index 4f7ee6a8..4421c816 100644 --- a/redis.go +++ b/redis.go @@ -67,6 +67,7 @@ type RedisClient interface { Publish(channel string, message interface{}) *redis.IntCmd XRead(a *redis.XReadArgs) *redis.XStreamSliceCmd XDel(stream string, ids ...string) *redis.IntCmd + HKeys(key string) *redis.StringSliceCmd HGetAll(key string) *redis.StringStringMapCmd TxPipelined(fn func(redis.Pipeliner) error) ([]redis.Cmder, error) Subscribe(channels ...string) *redis.PubSub @@ -220,6 +221,7 @@ func (rdbw *RDBWrapper) XRead(args *redis.XReadArgs) *redis.XStreamSliceCmd { return cmd } } + // Wrapper for connection handling func (rdbw *RDBWrapper) XDel(stream string, ids ...string) *redis.IntCmd { for { @@ -241,6 +243,27 @@ func (rdbw *RDBWrapper) XDel(stream string, ids ...string) *redis.IntCmd { } } +// Wrapper for connection handling +func (rdbw *RDBWrapper) HKeys(key string) *redis.StringSliceCmd { + for { + if !rdbw.IsConnected() { + rdbw.WaitForConnection() + continue + } + + cmd := rdbw.Rdb.HKeys(key) + _, err := cmd.Result() + + if err != nil { + if !rdbw.CheckConnection(false) { + continue + } + } + + return cmd + } +} + // Wrapper for auto-logging and connection handling func (rdbw *RDBWrapper) HGetAll(key string) (map[string]string, error) { for {