diff --git a/redis/redis.go b/redis/redis.go index 5ec6ad6..3f255bc 100644 --- a/redis/redis.go +++ b/redis/redis.go @@ -92,6 +92,35 @@ func (c Client) Close() error { return c.c.Close() } +// Return all the keys +func (c Client) Keys() ([]string, error) { + var keys []string + var cursor uint64 + var err error + + for { + var batch []string + + if batch, cursor, err = c.c.Scan(context.Background(), cursor, "*", 10).Result(); err != nil { + return nil, err + } + + for _, key := range batch { + keys = append(keys, key) + } + + if cursor == 0 { + break + } + } + + if len(keys) == 0 { + return nil, nil + } + + return keys, nil +} + // Options are the options for the Redis client. type Options struct { // Address of the Redis server, including the port.