cache icon indicating copy to clipboard operation
cache copied to clipboard

Is there any way to flushdb with go redis cache?

Open lqn0011 opened this issue 2 years ago • 2 comments

How can we clear all cache with a function call?

lqn0011 avatar Jul 25 '22 10:07 lqn0011

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())
	}
}

nwtnsqrd avatar Nov 03 '22 14:11 nwtnsqrd

Thanks, this one is straightforward🤝.

lqn0011 avatar Nov 16 '22 01:11 lqn0011