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
170 171 172 173 174 175 176 177 178 179 |
# File 'lib/redis/dump.rb', line 170 def dump(this_redis, key, type=nil) type ||= type(this_redis, key) info = { 'db' => this_redis.client.db, 'key' => key } info['ttl'] = this_redis.ttl key info['type'] = type info['value'] = value(this_redis, key, info['type']) info['size'] = stringify(this_redis, key, info['type'], info['value']).size #ld "dump[#{this_redis.hash}, #{info}]" info end |
#dump_strings(this_redis, keys) ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/redis/dump.rb', line 180 def dump_strings(this_redis, keys) vals = this_redis.mget *keys idx = -1 keys.collect { |key| idx += 1 info = { 'db' => this_redis.client.db, 'key' => key, 'ttl' => this_redis.ttl(key), 'type' => 'string', 'value' => vals[idx].to_s, 'size' => vals[idx].to_s.size } block_given? ? yield(info) : info } end |
#report(this_redis, key) ⇒ Object
162 163 164 165 166 167 168 169 |
# File 'lib/redis/dump.rb', line 162 def report(this_redis, key) info = { 'db' => this_redis.client.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 #ld "report[#{this_redis.hash}, #{info}]" info end |
#set_value(this_redis, key, type, value, expire = nil) ⇒ Object
193 194 195 196 197 |
# File 'lib/redis/dump.rb', line 193 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
205 206 207 |
# File 'lib/redis/dump.rb', line 205 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
208 209 210 |
# File 'lib/redis/dump.rb', line 208 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
220 221 222 |
# File 'lib/redis/dump.rb', line 220 def set_value_none(this_redis, key, str) # ignore end |
#set_value_set(this_redis, key, set) ⇒ Object
211 212 213 |
# File 'lib/redis/dump.rb', line 211 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
217 218 219 |
# File 'lib/redis/dump.rb', line 217 def set_value_string(this_redis, key, str) this_redis.set key, str end |
#set_value_zset(this_redis, key, zset) ⇒ Object
214 215 216 |
# File 'lib/redis/dump.rb', line 214 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
201 202 203 |
# File 'lib/redis/dump.rb', line 201 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
234 |
# File 'lib/redis/dump.rb', line 234 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
231 |
# File 'lib/redis/dump.rb', line 231 def stringify_list (this_redis, key, v=nil) (v || value_list(this_redis, key)).join end |
#stringify_none(this_redis, key, v = nil) ⇒ Object
235 |
# File 'lib/redis/dump.rb', line 235 def stringify_none (this_redis, key, v=nil) (v || '') end |
#stringify_set(this_redis, key, v = nil) ⇒ Object
232 |
# File 'lib/redis/dump.rb', line 232 def stringify_set (this_redis, key, v=nil) (v || value_set(this_redis, key)).join end |
#stringify_string(this_redis, key, v = nil) ⇒ Object
230 |
# File 'lib/redis/dump.rb', line 230 def stringify_string(this_redis, key, v=nil) (v || value_string(this_redis, key)) end |
#stringify_zset(this_redis, key, v = nil) ⇒ Object
233 |
# File 'lib/redis/dump.rb', line 233 def stringify_zset (this_redis, key, v=nil) (v || value_zset(this_redis, key)).flatten.compact.join end |
#type(this_redis, key) ⇒ Object
157 158 159 160 161 |
# File 'lib/redis/dump.rb', line 157 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
198 199 200 |
# File 'lib/redis/dump.rb', line 198 def value(this_redis, key, t=nil) send("value_#{t}", this_redis, key) end |
#value_hash(this_redis, key) ⇒ Object
228 |
# File 'lib/redis/dump.rb', line 228 def value_hash (this_redis, key) this_redis.hgetall(key) end |
#value_list(this_redis, key) ⇒ Object
225 |
# File 'lib/redis/dump.rb', line 225 def value_list (this_redis, key) this_redis.lrange key, 0, -1 end |
#value_none(this_redis, key) ⇒ Object
229 |
# File 'lib/redis/dump.rb', line 229 def value_none (this_redis, key) '' end |
#value_set(this_redis, key) ⇒ Object
226 |
# File 'lib/redis/dump.rb', line 226 def value_set (this_redis, key) this_redis.smembers key end |
#value_string(this_redis, key) ⇒ Object
224 |
# File 'lib/redis/dump.rb', line 224 def value_string(this_redis, key) this_redis.get key end |
#value_zset(this_redis, key) ⇒ Object
227 |
# File 'lib/redis/dump.rb', line 227 def value_zset (this_redis, key) this_redis.zrange(key, 0, -1, :with_scores => true).tuple end |