Skip to content

Commit 4c15693

Browse files
committed
feat(goredis): optimize DelGroup to use single Redis DEL command
Instead of sending multiple individual DEL commands in a pipeline, collect all keys and send a single DEL command with multiple keys. This reduces network overhead and improves performance for bulk deletions. Fixes #18
1 parent 587a472 commit 4c15693

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

stores/goredis/redis.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -278,15 +278,16 @@ func (s *Store) Del(namespace, group, uri string) error {
278278

279279
// DelGroup deletes a whole group.
280280
func (s *Store) DelGroup(namespace string, groups ...string) error {
281-
p := s.cn.Pipeline()
282-
for _, group := range groups {
283-
if err := p.Del(s.ctx, s.key(namespace, group)).Err(); err != nil {
284-
return err
285-
}
281+
if len(groups) == 0 {
282+
return nil
286283
}
287284

288-
_, err := p.Exec(s.ctx)
289-
return err
285+
keys := make([]string, len(groups))
286+
for i, group := range groups {
287+
keys[i] = s.key(namespace, group)
288+
}
289+
290+
return s.cn.Del(s.ctx, keys...).Err()
290291
}
291292

292293
func (s *Store) key(namespace, group string) string {

0 commit comments

Comments
 (0)