redisdb/del_with_prefix.go

21 lines
466 B
Go
Raw Normal View History

2021-08-09 03:36:09 +00:00
package redisdb
import (
"context"
"fmt"
)
// DelWithPrefix ...
func (s Server) DelWithPrefix(ctx context.Context, prefix string) {
iter := s.rdb.Scan(ctx, 0, prefix, 0).Iterator()
2021-08-09 03:36:09 +00:00
for iter.Next(ctx) {
err := s.rdb.Del(ctx, iter.Val()).Err()
2021-08-09 03:36:09 +00:00
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
}
}