go-redis / cache

Cache library with Redis backend for Golang
https://redis.uptrace.dev/guide/go-redis-cache.html
BSD 2-Clause "Simplified" License
757 stars 95 forks source link

Is there any way to flushdb with go redis cache? #85

Open lqn0011 opened 2 years ago

lqn0011 commented 2 years ago

How can we clear all cache with a function call?

nwtnsqrd commented 2 years ago

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())
    }
}
lqn0011 commented 2 years ago

Thanks, this one is straightforward🤝.