Module: SidekiqUniqueJobs::Digests
- Extended by:
- Digests
- Includes:
- Connection, Logging
- Included in:
- Digests
- Defined in:
- lib/sidekiq_unique_jobs/digests.rb
Overview
Utility module to help manage unique digests in redis.
Constant Summary collapse
- DEFAULT_COUNT =
1_000- SCAN_PATTERN =
'*'- CHUNK_SIZE =
100
Instance Method Summary collapse
-
#all(pattern: SCAN_PATTERN, count: DEFAULT_COUNT) ⇒ Array<String>
Return unique digests matching pattern.
-
#count ⇒ Integer
Get a total count of unique digests.
-
#del(digest: nil, pattern: nil, count: DEFAULT_COUNT) ⇒ Array<String>
Deletes unique digest either by a digest or pattern.
-
#page(pattern: SCAN_PATTERN, cursor: 0, page_size: 100) ⇒ Array<String>
Paginate unique digests.
Methods included from Connection
Methods included from Logging
#log_debug, #log_error, #log_fatal, #log_info, #log_warn, #logger, #logging_context
Instance Method Details
#all(pattern: SCAN_PATTERN, count: DEFAULT_COUNT) ⇒ Array<String>
Return unique digests matching pattern
21 22 23 |
# File 'lib/sidekiq_unique_jobs/digests.rb', line 21 def all(pattern: SCAN_PATTERN, count: DEFAULT_COUNT) redis { |conn| conn.sscan_each(UNIQUE_SET, match: pattern, count: count).to_a } end |
#count ⇒ Integer
Get a total count of unique digests
45 46 47 |
# File 'lib/sidekiq_unique_jobs/digests.rb', line 45 def count redis { |conn| conn.scard(UNIQUE_SET) } end |
#del(digest: nil, pattern: nil, count: DEFAULT_COUNT) ⇒ Array<String>
Deletes unique digest either by a digest or pattern
56 57 58 59 60 61 |
# File 'lib/sidekiq_unique_jobs/digests.rb', line 56 def del(digest: nil, pattern: nil, count: DEFAULT_COUNT) return delete_by_pattern(pattern, count: count) if pattern return delete_by_digest(digest) if digest raise ArgumentError, 'either digest or pattern need to be provided' end |
#page(pattern: SCAN_PATTERN, cursor: 0, page_size: 100) ⇒ Array<String>
Paginate unique digests
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/sidekiq_unique_jobs/digests.rb', line 31 def page(pattern: SCAN_PATTERN, cursor: 0, page_size: 100) redis do |conn| total_size, digests = conn.multi do conn.scard(UNIQUE_SET) conn.sscan(UNIQUE_SET, cursor, match: pattern, count: page_size) end [total_size, digests[0], digests[1]] end end |