1- package redis
1+ package redis
22
33import (
44 "context"
@@ -16,6 +16,7 @@ type RedisClient interface {
1616 HSet (ctx context.Context , key string , values ... interface {}) * redis.IntCmd
1717 RPush (ctx context.Context , key string , value interface {}) * redis.IntCmd
1818 LRange (ctx context.Context , key string , start , stop int64 ) * redis.StringSliceCmd
19+ FlushAll (ctx context.Context ) error
1920}
2021
2122/* redisClient implementation */
@@ -33,7 +34,7 @@ func NewRedisClient(address, password string, db int) (RedisClient, error) {
3334
3435 ctx , cancel := context .WithTimeout (context .Background (), 5 * time .Second )
3536 defer cancel ()
36-
37+
3738 if err := rdb .Ping (ctx ).Err (); err != nil {
3839 return nil , fmt .Errorf ("could not connect to Redis: %w" , err )
3940 }
@@ -70,3 +71,8 @@ func (r *redisClient) LRange(ctx context.Context, key string, start, stop int64)
7071func (r * redisClient ) HSet (ctx context.Context , key string , values ... interface {}) * redis.IntCmd {
7172 return r .client .HSet (ctx , key , values ... )
7273}
74+
75+ /* flush all data from Redis */
76+ func (r * redisClient ) FlushAll (ctx context.Context ) error {
77+ return r .client .FlushAll (ctx ).Err ()
78+ }
0 commit comments