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.
5 6 7 8 |
# File 'lib/redis_scanner/redis.rb', line 5 def initialize() @options = @client = ::Redis.new () end |
Instance Attribute Details
#client ⇒ Object (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_keys ⇒ Object
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 |