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

- old
+ new

@@ -8,40 +8,32 @@ "#{ Tally.config.prefix }@#{ day_key }" end private - def all_keys - @keys ||= build_keys_from_redis - end - - def build_keys_from_redis - result = [] - cursor = "" - - scan = scan_from_redis - - while cursor != "0" - result << scan.last - cursor = scan.first - - scan = scan_from_redis(cursor: cursor) - end - - result.flatten - end - def day_key @day_key ||= day.strftime(Tally.config.date_format) end def entry_regex @entry_regex ||= Regexp.new("(?<record>[^:]+:[\\d]+)?:?(?<key>[^:]+)") end def scan_from_redis(cursor: "0") - Tally.redis do |conn| - conn.sscan(daily_key, cursor, match: scan_key, count: 25) + 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.sscan(daily_key, "MATCH", scan_key, "COUNT", 25).to_a + ] + end + else + Tally.redis do |conn| + conn.sscan(daily_key, cursor, match: scan_key, count: 25) + end end end def scan_key @scan_key ||= if key.present? && record.present?