Module: Redis::Helpers::CoreCommands
- Defined in:
- lib/redis/helpers/core_commands.rb
Overview
These are core commands that all types share (rename, etc)
Instance Method Summary collapse
- #delete ⇒ Object (also: #del, #clear)
- #exists? ⇒ Boolean
- #expire(seconds) ⇒ Object
- #expireat(unixtime) ⇒ Object
- #marshal(value, domarshal = false) ⇒ Object
- #move(dbindex) ⇒ Object
- #persist ⇒ Object
- #rename(name, setkey = true) ⇒ Object
- #renamenx(name, setkey = true) ⇒ Object
- #sort(options = {}) ⇒ Object
- #ttl ⇒ Object
- #type ⇒ Object
- #unmarshal(value, domarshal = false) ⇒ Object
Instance Method Details
#delete ⇒ Object Also known as: del, clear
9 10 11 |
# File 'lib/redis/helpers/core_commands.rb', line 9 def delete redis.del key end |
#exists? ⇒ Boolean
5 6 7 |
# File 'lib/redis/helpers/core_commands.rb', line 5 def exists? redis.exists key end |
#expire(seconds) ⇒ Object
33 34 35 |
# File 'lib/redis/helpers/core_commands.rb', line 33 def expire(seconds) redis.expire key, seconds end |
#expireat(unixtime) ⇒ Object
37 38 39 |
# File 'lib/redis/helpers/core_commands.rb', line 37 def expireat(unixtime) redis.expireat key, unixtime end |
#marshal(value, domarshal = false) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/redis/helpers/core_commands.rb', line 59 def marshal(value, domarshal=false) if [:marshal] || domarshal Marshal.dump(value) else value end end |
#move(dbindex) ⇒ Object
49 50 51 |
# File 'lib/redis/helpers/core_commands.rb', line 49 def move(dbindex) redis.move key, dbindex end |
#persist ⇒ Object
41 42 43 |
# File 'lib/redis/helpers/core_commands.rb', line 41 def persist redis.persist key end |
#rename(name, setkey = true) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/redis/helpers/core_commands.rb', line 19 def rename(name, setkey=true) dest = name.is_a?(self.class) ? name.key : name ret = redis.rename key, dest @key = dest if ret && setkey ret end |
#renamenx(name, setkey = true) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/redis/helpers/core_commands.rb', line 26 def renamenx(name, setkey=true) dest = name.is_a?(self.class) ? name.key : name ret = redis.renamenx key, dest @key = dest if ret && setkey ret end |
#sort(options = {}) ⇒ Object
53 54 55 56 57 |
# File 'lib/redis/helpers/core_commands.rb', line 53 def sort(={}) [:order] = "asc alpha" if .keys.count == 0 # compat with Ruby val = redis.sort(key, ) val.is_a?(Array) ? val.map{|v| unmarshal(v)} : val end |
#ttl ⇒ Object
45 46 47 |
# File 'lib/redis/helpers/core_commands.rb', line 45 def ttl redis.ttl(@key) end |
#type ⇒ Object
15 16 17 |
# File 'lib/redis/helpers/core_commands.rb', line 15 def type redis.type key end |
#unmarshal(value, domarshal = false) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/redis/helpers/core_commands.rb', line 67 def unmarshal(value, domarshal=false) if value.nil? nil elsif [:marshal] || domarshal Marshal.load(value) else value end end |