Module: RedisCluster::Function::Key
- Included in:
- RedisCluster::Function
- Defined in:
- lib/redis_cluster/function/key.rb
Overview
Key implement redis keys commands. There will be some adjustment for cluster. see redis.io/commands#generic. Most of the code are copied from github.com/redis/redis-rb/blob/master/lib/redis.rb.
SETTER = [:del, :expire, :pexpire, :restore] GETTER = [:exists, :ttl, :pttl, :type]
Instance Method Summary collapse
-
#del(key) ⇒ Boolean
Delete one key.
-
#dump(key) ⇒ String
Return a serialized version of the value stored at a key.
-
#exists(key) ⇒ Boolean
Determine if a key exists.
-
#expire(key, seconds) ⇒ Boolean
Set a key’s time to live in seconds.
-
#pexpire(key, milliseconds) ⇒ Boolean
Set a key’s time to live in milliseconds.
-
#pttl(key) ⇒ Fixnum
Get the time to live (in milliseconds) for a key.
-
#restore(key, ttl, serialized_value, option = {}) ⇒ String
Create a key using the serialized value, previously obtained using DUMP.
-
#ttl(key) ⇒ Fixnum
Get the time to live (in seconds) for a key.
-
#type(key) ⇒ String
Determine the type stored at key.
Instance Method Details
#del(key) ⇒ Boolean
Delete one key.
20 21 22 |
# File 'lib/redis_cluster/function/key.rb', line 20 def del(key) call(key, [:del, key], transform: Redis::Boolify) end |
#dump(key) ⇒ String
Return a serialized version of the value stored at a key.
103 104 105 |
# File 'lib/redis_cluster/function/key.rb', line 103 def dump(key) call(key, [:dump, key], read: true) end |
#exists(key) ⇒ Boolean
Determine if a key exists.
46 47 48 |
# File 'lib/redis_cluster/function/key.rb', line 46 def exists(key) call(key, [:exists, key], transform: Redis::Boolify, read: true) end |
#expire(key, seconds) ⇒ Boolean
Set a key’s time to live in seconds.
29 30 31 |
# File 'lib/redis_cluster/function/key.rb', line 29 def expire(key, seconds) call(key, [:expire, key, seconds], transform: Redis::Boolify) end |
#pexpire(key, milliseconds) ⇒ Boolean
Set a key’s time to live in milliseconds.
38 39 40 |
# File 'lib/redis_cluster/function/key.rb', line 38 def pexpire(key, milliseconds) call(key, [:pexpire, key, milliseconds], transform: Redis::Boolify) end |
#pttl(key) ⇒ Fixnum
Get the time to live (in milliseconds) for a key.
Starting with Redis 2.8 the return value in case of error changed:
- The command returns -2 if the key does not exist.
- The command returns -1 if the key exists but has no associated expire.
72 73 74 |
# File 'lib/redis_cluster/function/key.rb', line 72 def pttl(key) call(key, [:pttl, key], read: true) end |
#restore(key, ttl, serialized_value, option = {}) ⇒ String
Create a key using the serialized value, previously obtained using DUMP.
92 93 94 95 96 97 |
# File 'lib/redis_cluster/function/key.rb', line 92 def restore(key, ttl, serialized_value, option = {}) args = [:restore, key, ttl, serialized_value] args << 'REPLACE' if option[:replace] call(key, args) end |
#ttl(key) ⇒ Fixnum
Get the time to live (in seconds) for a key.
Starting with Redis 2.8 the return value in case of error changed:
- The command returns -2 if the key does not exist.
- The command returns -1 if the key exists but has no associated expire.
59 60 61 |
# File 'lib/redis_cluster/function/key.rb', line 59 def ttl(key) call(key, [:ttl, key], read: true) end |
#type(key) ⇒ String
Determine the type stored at key.
80 81 82 |
# File 'lib/redis_cluster/function/key.rb', line 80 def type(key) call(key, [:type, key], read: true) end |