Skip to content

Conversation

@tleish
Copy link
Contributor

@tleish tleish commented Jun 15, 2022

SUMMARY

This PR updates the existing Kredis::Migration#delete_all method to:

  • Allow a key pattern OR array passed to delete keys
  • Add logging for #delete_all

DETAILS

There's occasion where you might want to clear a large number of keys, but using a pattern creates too broad of a stroke.

Today, you would have to run:

found_users.each { |user| user.my_kredis_key.clear }

A much more efficient method would be to delete a list of keys in batch rather than separately:

Kredis.redis.del *found_users.map { |user| user.my_kredis_key.key }

This change add DSL to the process and logging of the event:

Kredis::Migration.delete_all *found_users.map { |user| user.my_kredis_key.key }

@tleish tleish changed the title Delete all keys Delete list of keys in batch Jun 15, 2022
@dhh dhh merged commit 476069f into rails:main Jun 18, 2022
lewispb added a commit to lewispb/kredis that referenced this pull request Jul 1, 2022
* main:
  Coalesce "current pipeline or redis" into the redis method itself
  Pefer a thread_mattr_accessor over a thread local variable
  Delete list of keys in batch (rails#90)
  Use a thread-local variable for pipeline
  Revert "Use block parameter to pipeline in Redis#multi (rails#68)"
  Resolve pipelining deprecation warnings
lewispb added a commit to lewispb/kredis that referenced this pull request Jul 1, 2022
* main:
  Coalesce "current pipeline or redis" into the redis method itself
  Pefer a thread_mattr_accessor over a thread local variable
  Delete list of keys in batch (rails#90)
  Use a thread-local variable for pipeline
  Revert "Use block parameter to pipeline in Redis#multi (rails#68)"
  Resolve pipelining deprecation warnings
lewispb added a commit to lewispb/kredis that referenced this pull request Jun 19, 2023
* main: (21 commits)
  Bump version for 1.4.0
  Update nokogiri for compatibility
  Revert "Improved version of UniqueList: OrderedSet (rails#76)" (rails#111)
  Add `last` to lists (rails#97)
  Improved version of UniqueList: OrderedSet (rails#76)
  Return Time objects instead of deprecated DateTime (rails#106)
  Fix possible deserialization of untrusted data
  Typecast return of Set#take (rails#105)
  Declare Active Model dependency (rails#107)
  Address LogSubscriber deprecation (rails#98)
  Account for time zones in DateTime serializations (rails#102)
  Add sample to set (rails#100)
  Bump version for 1.3.0
  Allow Redis 5.x
  Add ltrim to lists
  Coalesce "current pipeline or redis" into the redis method itself
  Pefer a thread_mattr_accessor over a thread local variable
  Delete list of keys in batch (rails#90)
  Use a thread-local variable for pipeline
  Revert "Use block parameter to pipeline in Redis#multi (rails#68)"
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants