Class: RedisScanner::Redis

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Redis

Returns a new instance of Redis.



5
6
7
8
# File 'lib/redis_scanner/redis.rb', line 5

def initialize(options)
  @options = options
  @client = ::Redis.new extract_redis_options(options)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



3
4
5
# File 'lib/redis_scanner/redis.rb', line 3

def client
  @client
end

Instance Method Details

#get_type_and_size(key) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/redis_scanner/redis.rb', line 25

def get_type_and_size(key)
  type = @client.type key
  size = case type
    when "string"
      @client.strlen key
    when "list"
      @client.llen key
    when "hash"
      @client.hlen key
    when "set"
      @client.scard key
    when "zset"
      @client.zcard key
    else
      1
  end
  [type, size.to_i]
end

#scan(*args) ⇒ Object



10
11
12
# File 'lib/redis_scanner/redis.rb', line 10

def scan(*args)
  @client.scan *args
end

#total_keysObject

total keys for given db(default 0)



15
16
17
18
19
20
21
22
23
# File 'lib/redis_scanner/redis.rb', line 15

def total_keys
  ret = 0
  if (info = @client.info) && (str = info["db#{@options[:db].to_i}"])
    if m = str.scan(/keys=(\d+)/)
      ret = m.flatten.first.to_i
    end
  end
  ret
end