go-redis/cache

Is there any way to flushdb with go redis cache?

lqn0011 opened this issue · 2 comments

How can we clear all cache with a function call?

Hello, in case you still need an answer. You can use functionality from package https://github.com/go-redis/redis

var (
	rdb = redis.NewClient(&redis.Options{
		Addr: "localhost:6379",
		DB:   0,
	})
	ctx = context.Background()
)

func FlushRedisCache() {
	if _, err := rdb.Do(ctx, "flushdb").Result(); err != nil {
		fmt.Println("ERROR: Could not flush Redis cache:", err.Error())
	}
}

Thanks, this one is straightforward🤝.