Class: RedisScanner::Redis
- Inherits:
-
Object
- Object
- RedisScanner::Redis
- Defined in:
- lib/redis_scanner/redis.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #get_type_and_size(key) ⇒ Object
-
#initialize(options) ⇒ Redis
constructor
A new instance of Redis.
- #scan(*args) ⇒ Object
-
#total_keys ⇒ Object
total keys for given db(default 0).
Constructor Details
#initialize(options) ⇒ Redis
Returns a new instance of Redis.
7 8 9 10 |
# File 'lib/redis_scanner/redis.rb', line 7 def initialize() @options = @client = ::Redis.new () end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
5 6 7 |
# File 'lib/redis_scanner/redis.rb', line 5 def client @client end |
Instance Method Details
#get_type_and_size(key) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/redis_scanner/redis.rb', line 27 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
12 13 14 |
# File 'lib/redis_scanner/redis.rb', line 12 def scan(*args) @client.scan *args end |
#total_keys ⇒ Object
total keys for given db(default 0)
17 18 19 20 21 22 23 24 25 |
# File 'lib/redis_scanner/redis.rb', line 17 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 |