redisdb/del_with_prefix.go

21 lines
451 B
Go
Raw Normal View History

2021-08-09 03:36:09 +00:00
package redisdb
import (
"context"
"fmt"
)
// DelWithPrefix ...
func DelWithPrefix(ctx context.Context, prefix string) {
iter := rdb.Scan(ctx, 0, prefix, 0).Iterator()
for iter.Next(ctx) {
err := rdb.Del(ctx, iter.Val()).Err()
if err != nil {
2022-12-05 07:54:51 +00:00
fmt.Println("[redisdb] cannot delete redis key with prefix", prefix)
2021-08-09 03:36:09 +00:00
}
}
if err := iter.Err(); err != nil {
2022-12-05 07:54:51 +00:00
fmt.Println("[redisdb] cannot (LOOP) delete redis key with prefix", prefix)
2021-08-09 03:36:09 +00:00
}
}