2021-08-09 03:36:09 +00:00
|
|
|
package redisdb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
// DelWithPrefix ...
|
2022-12-05 08:14:06 +00:00
|
|
|
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) {
|
2022-12-05 08:14:06 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|