Skip to content

Commit dfd2ff2

Browse files
Added flush command for Redis
1 parent 177a285 commit dfd2ff2

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

internal/redis/redis.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package redis
1+
package redis
22

33
import (
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)
7071
func (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

Comments
 (0)