Skip to content

Commit e0452e8

Browse files
authored
Merge pull request rails#54861 from roharon/optimize.activesupport.redis_cache_store
Use UNLINK for RedisCacheStore in ActiveSupport
2 parents 3a476b9 + 76ec98d commit e0452e8

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

activesupport/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Use `UNLINK` command instead of `DEL` in `ActiveSupport::Cache::RedisCacheStore` for non-blocking deletion.
2+
3+
*Aron Roh*
4+
15
* Add `Cache#read_counter` and `Cache#write_counter`
26

37
```ruby

activesupport/lib/active_support/cache/redis_cache_store.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def delete_matched(matcher, options = nil)
227227
nodes.each do |node|
228228
begin
229229
cursor, keys = node.scan(cursor, match: pattern, count: SCAN_BATCH_SIZE)
230-
node.del(*keys) unless keys.empty?
230+
node.unlink(*keys) unless keys.empty?
231231
end until cursor == "0"
232232
end
233233
end
@@ -408,14 +408,16 @@ def write_serialized_entry(key, payload, raw: false, unless_exist: false, expire
408408
# Delete an entry from the cache.
409409
def delete_entry(key, **options)
410410
failsafe :delete_entry, returning: false do
411-
redis.then { |c| c.del(key) == 1 }
411+
redis.then { |c| c.unlink(key) == 1 }
412412
end
413413
end
414414

415415
# Deletes multiple entries in the cache. Returns the number of entries deleted.
416416
def delete_multi_entries(entries, **_options)
417+
return 0 if entries.empty?
418+
417419
failsafe :delete_multi_entries, returning: 0 do
418-
redis.then { |c| c.del(entries) }
420+
redis.then { |c| c.unlink(*entries) }
419421
end
420422
end
421423

0 commit comments

Comments
 (0)