lib/tally/key_finder.rb in tally-1.0.2 vs lib/tally/key_finder.rb in tally-2.0.0

- old
+ new

@@ -71,22 +71,20 @@ @keys ||= build_keys_from_redis end def build_keys_from_redis result = [] - cursor = "" + cursor = nil - scan = scan_from_redis - while cursor != "0" + scan = scan_from_redis(cursor: cursor.presence || "0") + result << scan.last cursor = scan.first - - scan = scan_from_redis(cursor: cursor) end - result.flatten + result.flatten.uniq end def day_key @day_key ||= if day == "*" "*" @@ -98,10 +96,22 @@ def entry_regex @entry_regex ||= Regexp.new("#{ Tally.config.prefix }:?(?<record>[^:]+:[\\d]+)?:?(?<key>[^:]+)?@") end def scan_from_redis(cursor: "0") - Tally.redis { |conn| conn.scan(cursor, match: scan_key) } + klass = Tally.redis { |conn| conn.class.to_s } + + # if we're using sidekiq / RedisClient, scan needs a block, and doesn't worry about the cursor + if klass == "Sidekiq::RedisClientAdapter::CompatClient" + Tally.redis do |conn| + [ + "0", # fake cursor to match redis-rb output + conn.scan("MATCH", scan_key).to_a + ] + end + else + Tally.redis { |conn| conn.scan(cursor, match: scan_key) } + end end def scan_key @scan_key ||= if key.present? && record.present? "#{ Tally.config.prefix }:#{ record.model_name.i18n_key }:#{ record.id }:#{ key }@#{ day_key }"