Skip to content

Commit

Permalink
all: Avoid watching empty sets of keys
Browse files Browse the repository at this point in the history
  • Loading branch information
adriansmares committed Jul 26, 2023
1 parent c9022ba commit 19b668c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
9 changes: 7 additions & 2 deletions pkg/applicationserver/redis/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,13 @@ func (r *DeviceRegistry) BatchDelete(
}
}
}
if err := tx.Watch(ctx, euiKeys...).Err(); err != nil {
return err
// If the provided end device identifiers are not registered, it is possible
// that the `euiKeys` set will be empty. `WATCH` does not allow an empty set
// of keys to be provided, and as such must be manually skipped.
if len(euiKeys) > 0 {
if err := tx.Watch(ctx, euiKeys...).Err(); err != nil {
return err
}
}
if _, err := tx.TxPipelined(ctx, func(p redis.Pipeliner) error {
p.Del(ctx, append(uidKeys, euiKeys...)...)
Expand Down
9 changes: 7 additions & 2 deletions pkg/joinserver/redis/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -879,8 +879,13 @@ func (r *DeviceRegistry) BatchDelete(
}
}
}
if err := tx.Watch(ctx, keys...).Err(); err != nil {
return err
// If the provided end device identifiers are not registered, it is possible
// that the `keys` set will be empty. `WATCH` does not allow an empty set of
// keys to be provided, and as such must be manually skipped.
if len(keys) > 0 {
if err := tx.Watch(ctx, keys...).Err(); err != nil {
return err
}
}
if _, err := tx.TxPipelined(ctx, func(p redis.Pipeliner) error {
p.Del(ctx, append(uidKeys, keys...)...)
Expand Down
9 changes: 7 additions & 2 deletions pkg/networkserver/redis/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -1024,8 +1024,13 @@ func (r *DeviceRegistry) BatchDelete(
}
}
}
if err := tx.Watch(ctx, euiKeys...).Err(); err != nil {
return err
// If the provided end device identifiers are not registered, it is possible
// that the `euiKeys` set will be empty. `WATCH` does not allow an empty set
// of keys to be provided, and as such must be manually skipped.
if len(euiKeys) > 0 {
if err := tx.Watch(ctx, euiKeys...).Err(); err != nil {
return err
}
}
if _, err := tx.TxPipelined(ctx, func(p redis.Pipeliner) error {
p.Del(ctx, append(uidKeys, euiKeys...)...)
Expand Down

0 comments on commit 19b668c

Please sign in to comment.