Module: Redis::Dump::ClassMethods
- Included in:
- Redis::Dump
- Defined in:
- lib/redis/dump.rb
Instance Method Summary collapse
- #dump(this_redis, key, type = nil) ⇒ Object
- #dump_strings(this_redis, keys) ⇒ Object
- #report(this_redis, key) ⇒ Object
- #set_value(this_redis, key, type, value, expire = nil) ⇒ Object
- #set_value_hash(this_redis, key, hash) ⇒ Object
- #set_value_list(this_redis, key, list) ⇒ Object
- #set_value_none(this_redis, key, str) ⇒ Object
- #set_value_set(this_redis, key, set) ⇒ Object
- #set_value_string(this_redis, key, str) ⇒ Object
- #set_value_zset(this_redis, key, zset) ⇒ Object
- #stringify(this_redis, key, t = nil, v = nil) ⇒ Object
- #stringify_hash(this_redis, key, v = nil) ⇒ Object
- #stringify_list(this_redis, key, v = nil) ⇒ Object
- #stringify_none(this_redis, key, v = nil) ⇒ Object
- #stringify_set(this_redis, key, v = nil) ⇒ Object
- #stringify_string(this_redis, key, v = nil) ⇒ Object
- #stringify_zset(this_redis, key, v = nil) ⇒ Object
- #type(this_redis, key) ⇒ Object
- #value(this_redis, key, t = nil) ⇒ Object
- #value_hash(this_redis, key) ⇒ Object
- #value_list(this_redis, key) ⇒ Object
- #value_none(this_redis, key) ⇒ Object
- #value_set(this_redis, key) ⇒ Object
- #value_string(this_redis, key) ⇒ Object
- #value_zset(this_redis, key) ⇒ Object
Instance Method Details
#dump(this_redis, key, type = nil) ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/redis/dump.rb', line 198 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) ⇒ Object
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/redis/dump.rb', line 211 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) ⇒ Object
191 192 193 194 195 196 197 |
# File 'lib/redis/dump.rb', line 191 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) ⇒ Object
228 229 230 231 232 |
# File 'lib/redis/dump.rb', line 228 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) ⇒ Object
240 241 242 |
# File 'lib/redis/dump.rb', line 240 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) ⇒ Object
243 244 245 |
# File 'lib/redis/dump.rb', line 243 def set_value_list(this_redis, key, list) list.each { |value| this_redis.rpush key, value } end |
#set_value_none(this_redis, key, str) ⇒ Object
255 256 257 |
# File 'lib/redis/dump.rb', line 255 def set_value_none(this_redis, key, str) # ignore end |
#set_value_set(this_redis, key, set) ⇒ Object
246 247 248 |
# File 'lib/redis/dump.rb', line 246 def set_value_set(this_redis, key, set) set.each { |value| this_redis.sadd? key, value } end |
#set_value_string(this_redis, key, str) ⇒ Object
252 253 254 |
# File 'lib/redis/dump.rb', line 252 def set_value_string(this_redis, key, str) this_redis.set key, str end |
#set_value_zset(this_redis, key, zset) ⇒ Object
249 250 251 |
# File 'lib/redis/dump.rb', line 249 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) ⇒ Object
236 237 238 |
# File 'lib/redis/dump.rb', line 236 def stringify(this_redis, key, t=nil, v=nil) send("stringify_#{t}", this_redis, key, v) end |
#stringify_hash(this_redis, key, v = nil) ⇒ Object
269 |
# File 'lib/redis/dump.rb', line 269 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) ⇒ Object
266 |
# File 'lib/redis/dump.rb', line 266 def stringify_list (this_redis, key, v=nil) (v || value_list(this_redis, key)).join end |
#stringify_none(this_redis, key, v = nil) ⇒ Object
270 |
# File 'lib/redis/dump.rb', line 270 def stringify_none (this_redis, key, v=nil) (v || '') end |
#stringify_set(this_redis, key, v = nil) ⇒ Object
267 |
# File 'lib/redis/dump.rb', line 267 def stringify_set (this_redis, key, v=nil) (v || value_set(this_redis, key)).join end |
#stringify_string(this_redis, key, v = nil) ⇒ Object
265 |
# File 'lib/redis/dump.rb', line 265 def stringify_string(this_redis, key, v=nil) (v || value_string(this_redis, key)) end |
#stringify_zset(this_redis, key, v = nil) ⇒ Object
268 |
# File 'lib/redis/dump.rb', line 268 def stringify_zset (this_redis, key, v=nil) (v || value_zset(this_redis, key)).flatten.compact.join end |
#type(this_redis, key) ⇒ Object
186 187 188 189 190 |
# File 'lib/redis/dump.rb', line 186 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) ⇒ Object
233 234 235 |
# File 'lib/redis/dump.rb', line 233 def value(this_redis, key, t=nil) send("value_#{t}", this_redis, key) end |
#value_hash(this_redis, key) ⇒ Object
263 |
# File 'lib/redis/dump.rb', line 263 def value_hash (this_redis, key) this_redis.hgetall(key) end |
#value_list(this_redis, key) ⇒ Object
260 |
# File 'lib/redis/dump.rb', line 260 def value_list (this_redis, key) this_redis.lrange key, 0, -1 end |
#value_none(this_redis, key) ⇒ Object
264 |
# File 'lib/redis/dump.rb', line 264 def value_none (this_redis, key) '' end |
#value_set(this_redis, key) ⇒ Object
261 |
# File 'lib/redis/dump.rb', line 261 def value_set (this_redis, key) this_redis.smembers key end |
#value_string(this_redis, key) ⇒ Object
259 |
# File 'lib/redis/dump.rb', line 259 def value_string(this_redis, key) this_redis.get key end |
#value_zset(this_redis, key) ⇒ Object
262 |
# File 'lib/redis/dump.rb', line 262 def value_zset (this_redis, key) this_redis.zrange(key, 0, -1, :with_scores => true).flatten.tuple end |