Class: Rediscan

Inherits:
Object
  • Object
show all
Defined in:
lib/rediscan.rb

Instance Method Summary collapse

Constructor Details

#initialize(redis) ⇒ Rediscan

Returns a new instance of Rediscan.



2
3
4
5
# File 'lib/rediscan.rb', line 2

def initialize(redis)
  @redis = redis
  @cursor = "0"
end

Instance Method Details

#each(match: nil, count: nil, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rediscan.rb', line 7

def each(match: nil, count: nil, &block)
  done = false
  args = []
  args.push("MATCH", match) if match
  args.push("COUNT", count) if count

  until done
    @cursor, keys = @redis.call("SCAN", @cursor, *args)
    done = @cursor == "0"

    keys.each(&block)
  end
end