module Redis::Dump::ClassMethods

  1. lib/redis/dump.rb

Public Instance methods

dump (this_redis, key, type=nil)
[show source]
# File lib/redis/dump.rb, line 187
def dump(this_redis, key, type=nil)
  type ||= type(this_redis, key)
  info = { 'db' => this_redis.connection[:db], 'key' => key }
  info['ttl'] = this_redis.ttl key
  info['type'] = type
  stringified = stringify(this_redis, key, info['type'], info['value'])
  info['value'] = value(this_redis, key, info['type'])
  info['size'] = stringified.size
  if Redis::Dump.with_base64 && type === 'string'
    info['value'] = Base64.encode64(info['value'])
  end
  info
end
dump_strings (this_redis, keys)
[show source]
# File lib/redis/dump.rb, line 200
def dump_strings(this_redis, keys)
  vals = this_redis.mget *keys
  idx = -1
  keys.collect { |key|
    idx += 1
    val = vals[idx].to_s
    info = {
      'db'    => this_redis.connection[:db],
      'key'   => key,
      'ttl'   => this_redis.ttl(key),
      'type'  => 'string',
      'value' => Redis::Dump.with_base64 ? Base64.encode64(val) : val,
      'size'  => vals[idx].to_s.size
    }
    block_given? ? yield(info) : info
  }
end
report (this_redis, key)
[show source]
# File lib/redis/dump.rb, line 180
def report(this_redis, key)
  info = { 'db' => this_redis.connection[:db], 'key' => key }
  info['type'] = type(this_redis, key)
  info['size'] = stringify(this_redis, key, info['type'], info['value']).size
  info['bytes'] = info['size'].to_bytes
  info
end
set_value (this_redis, key, type, value, expire=nil)
[show source]
# File lib/redis/dump.rb, line 217
def set_value(this_redis, key, type, value, expire=nil)
  t ||= type
  send("set_value_#{t}", this_redis, key, value)
  this_redis.expire key, expire if expire.to_s.to_i > 0
end
set_value_hash (this_redis, key, hash)
[show source]
# File lib/redis/dump.rb, line 229
def set_value_hash(this_redis, key, hash)
  hash.keys.each { |k|  this_redis.hset key, k, hash[k] }
end
set_value_list (this_redis, key, list)
[show source]
# File lib/redis/dump.rb, line 232
def set_value_list(this_redis, key, list)
  list.each { |value|  this_redis.rpush key, value }
end
set_value_none (this_redis, key, str)
[show source]
# File lib/redis/dump.rb, line 244
def set_value_none(this_redis, key, str)
  # ignore
end
set_value_set (this_redis, key, set)
[show source]
# File lib/redis/dump.rb, line 235
def set_value_set(this_redis, key, set)
  set.each { |value|  this_redis.sadd key, value }
end
set_value_string (this_redis, key, str)
[show source]
# File lib/redis/dump.rb, line 241
def set_value_string(this_redis, key, str)
  this_redis.set key, str
end
set_value_zset (this_redis, key, zset)
[show source]
# File lib/redis/dump.rb, line 238
def set_value_zset(this_redis, key, zset)
  zset.each { |pair|  this_redis.zadd key, pair[1].to_f, pair[0] }
end
stringify (this_redis, key, t=nil, v=nil)
[show source]
# File lib/redis/dump.rb, line 225
def stringify(this_redis, key, t=nil, v=nil)
  send("stringify_#{t}", this_redis, key, v)
end
stringify_hash (this_redis, key, v=nil)
[show source]
# File lib/redis/dump.rb, line 258
def stringify_hash  (this_redis, key, v=nil)  (v || value_hash(this_redis, key)).to_a.flatten.compact.join  end
stringify_list (this_redis, key, v=nil)
[show source]
# File lib/redis/dump.rb, line 255
def stringify_list  (this_redis, key, v=nil)  (v || value_list(this_redis, key)).join                       end
stringify_none (this_redis, key, v=nil)
[show source]
# File lib/redis/dump.rb, line 259
def stringify_none  (this_redis, key, v=nil)  (v || '')                                                     end
stringify_set (this_redis, key, v=nil)
[show source]
# File lib/redis/dump.rb, line 256
def stringify_set   (this_redis, key, v=nil)  (v || value_set(this_redis, key)).join                        end
stringify_string (this_redis, key, v=nil)
[show source]
# File lib/redis/dump.rb, line 254
def stringify_string(this_redis, key, v=nil)  (v || value_string(this_redis, key))                          end
stringify_zset (this_redis, key, v=nil)
[show source]
# File lib/redis/dump.rb, line 257
def stringify_zset  (this_redis, key, v=nil)  (v || value_zset(this_redis, key)).flatten.compact.join       end
type (this_redis, key)
[show source]
# File lib/redis/dump.rb, line 175
def type(this_redis, key)
  type = this_redis.type key
  raise TypeError, "Unknown type: #{type}" if !VALID_TYPES.member?(type)
  type
end
value (this_redis, key, t=nil)
[show source]
# File lib/redis/dump.rb, line 222
def value(this_redis, key, t=nil)
  send("value_#{t}", this_redis, key)
end
value_hash (this_redis, key)
[show source]
# File lib/redis/dump.rb, line 252
def value_hash  (this_redis, key)  this_redis.hgetall(key)                                                  end
value_list (this_redis, key)
[show source]
# File lib/redis/dump.rb, line 249
def value_list  (this_redis, key)  this_redis.lrange key, 0, -1                                             end
value_none (this_redis, key)
[show source]
# File lib/redis/dump.rb, line 253
def value_none  (this_redis, key)  ''                                                                       end
value_set (this_redis, key)
[show source]
# File lib/redis/dump.rb, line 250
def value_set   (this_redis, key)  this_redis.smembers key                                                  end
value_string (this_redis, key)
[show source]
# File lib/redis/dump.rb, line 248
def value_string(this_redis, key)  this_redis.get key                                                       end
value_zset (this_redis, key)
[show source]
# File lib/redis/dump.rb, line 251
def value_zset  (this_redis, key)  this_redis.zrange(key, 0, -1, :with_scores => true).flatten.tuple        end