-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[multi-operations] redis: delete matched proto
- Loading branch information
Showing
4 changed files
with
105 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
class AnyCache::Adapters::Redis | ||
class DeleteMatchedBasic | ||
# @since 0.3.0 | ||
extend Forwardable | ||
|
||
# @return [String] | ||
# | ||
# @api private | ||
# @since 0.3.0 | ||
CURSOR_LOOP_FLAG = "0" | ||
|
||
# @return [Integer] | ||
# | ||
# @api private | ||
# @since 0.3.0 | ||
BATCH_SIZE = 10 | ||
|
||
# @return [AnyCache::Adapters::Redis] | ||
# | ||
# @api private | ||
# @since 0.3.0 | ||
attr_reader :adapter | ||
|
||
# @param adapter [AnyCache::Adapters::Redis] | ||
# @return [void] | ||
# | ||
# @api private | ||
# @since 0.3.0 | ||
def initiaalize(adapter) | ||
@adapter = adapter | ||
end | ||
|
||
# @!method delete_matched(pattern, **options) | ||
# @param pattern [Object] | ||
# @param options [Hash] | ||
# @return [void] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
class AnyCache::Adapters::Redis | ||
class DeleteMatchedHeavy < DeleteMatchedBasic | ||
# @param pattern [Regexp] | ||
# @param options [Hash] | ||
# @return [void] | ||
# | ||
# @api private | ||
# @since 0.3.0 | ||
def delete_matched(pattern, **options) | ||
cursor = CURSOR_LOOP_FLAG | ||
|
||
loop do | ||
cursor, keys = adapter.scan(cursor, count: BATCH_SIZE) | ||
adapter.del(keys.grep(pattern)) | ||
break if cursor == CURSOR_LOOP_FLAG | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
class AnyCache::Adapters::Redis | ||
class DeleteMatchedSoftly < DeleteMatchedBasic | ||
# @param pattern [String] | ||
# @param options [Hash] | ||
# @return [void] | ||
# | ||
# @api private | ||
# @since 0.3.0 | ||
def delete_matched(pattern, **options) | ||
cursor = CURSOR_LOOP_FLAG | ||
|
||
loop do | ||
cursor, keys = adapter.scan(cursor, match: pattern, count: BATCH_SIZE) | ||
adapter.del(keys) | ||
break if cursor == CURSOR_LOOP_FLAG | ||
end | ||
end | ||
end | ||
end |