Module: RedisCluster::Function::Scan

Included in:
RedisCluster::Function
Defined in:
lib/redis_cluster/function/scan.rb

Overview

Scan is a collection of redis scan functions

Constant Summary collapse

HSCAN =
->(v){ [v[0], v[1].each_slice(2).to_a] }
ZSCAN =
->(v){ [v[0], Redis::FloatifyPairs.call(v[1])] }

Instance Method Summary collapse

Instance Method Details

#hscan(key, cursor, options = {}) ⇒ String, Array<[String, String]>

Scan a hash

Examples:

Retrieve the first batch of key/value pairs in a hash

redis.hscan("hash", 0)

Parameters:

  • cursor (String, Integer)

    the cursor of the iteration

  • options (Hash) (defaults to: {})
    • ‘:match => String`: only return keys matching the pattern

    • ‘:count => Integer`: return count keys at most per iteration

Returns:



44
45
46
47
48
49
50
# File 'lib/redis_cluster/function/scan.rb', line 44

def hscan(key, cursor, options = {})
  args = [:hscan, key, cursor]
  args.push('MATCH', options[:match]) if options[:match]
  args.push('COUNT', options[:count]) if options[:count]

  call(key, args, transform: HSCAN, read: true)
end

#sscan(key, cursor, options = {}) ⇒ String+

Scan a set

Examples:

Retrieve the first batch of keys in a set

redis.sscan("set", 0)

Parameters:

  • cursor (String, Integer)

    the cursor of the iteration

  • options (Hash) (defaults to: {})
    • ‘:match => String`: only return keys matching the pattern

    • ‘:count => Integer`: return count keys at most per iteration

Returns:

  • (String, Array<String>)

    the next cursor and all found members



63
64
65
66
67
68
69
# File 'lib/redis_cluster/function/scan.rb', line 63

def sscan(key, cursor, options = {})
  args = [:sscan, key, cursor]
  args.push('MATCH', options[:match]) if options[:match]
  args.push('COUNT', options[:count]) if options[:count]

  call(key, args, read: true)
end

#zscan(key, cursor, options = {}) ⇒ String, Array<[String, Float]>

Scan a sorted set

Examples:

Retrieve the first batch of key/value pairs in a hash

redis.zscan("zset", 0)

Parameters:

  • cursor (String, Integer)

    the cursor of the iteration

  • options (Hash) (defaults to: {})
    • ‘:match => String`: only return keys matching the pattern

    • ‘:count => Integer`: return count keys at most per iteration

Returns:

  • (String, Array<[String, Float]>)

    the next cursor and all found members and scores



25
26
27
28
29
30
31
# File 'lib/redis_cluster/function/scan.rb', line 25

def zscan(key, cursor, options = {})
  args = [:zscan, key, cursor]
  args.push('MATCH', options[:match]) if options[:match]
  args.push('COUNT', options[:count]) if options[:count]

  call(key, args, transform: ZSCAN, read: true)
end