Method: Redis::Commands::Keys#scan

Defined in:
lib/redis/commands/keys.rb

#scan(cursor, **options) ⇒ String+

Scan the keyspace

See the Redis Server SCAN documentation for further details

Examples:

Retrieve the first batch of keys

redis.scan(0)
  # => ["4", ["key:21", "key:47", "key:42"]]

Retrieve a batch of keys matching a pattern

redis.scan(4, :match => "key:1?")
  # => ["92", ["key:13", "key:18"]]

Retrieve a batch of keys of a certain type

redis.scan(92, :type => "zset")
  # => ["173", ["sortedset:14", "sortedset:78"]]

Parameters:

  • cursor (String, Integer)

    the cursor of the iteration

  • options (Hash)
    • :match => String: only return keys matching the pattern
    • :count => Integer: return count keys at most per iteration
    • :type => String: return keys only of the given type

Returns:

  • (String, Array<String>)

    the next cursor and all found keys



27
28
29
# File 'lib/redis/commands/keys.rb', line 27

def scan(cursor, **options)
  _scan(:scan, cursor, [], **options)
end