Module: Familia::Horreum::Commands
- Included in:
- Familia::Horreum
- Defined in:
- lib/familia/horreum/commands.rb
Overview
Methods that call Redis commands (InstanceMethods)
NOTE: There is no hgetall for Horreum. This is because Horreum is a single hash in Redis that we aren’t meant to have be working on in memory for more than, making changes -> committing. To emphasize this, instead of “refreshing” the object with hgetall, just load the object again.
Instance Method Summary collapse
- #decr(field) ⇒ Object (also: #decrement)
- #decrby(field, decrement) ⇒ Object (also: #decrementby)
- #exists? ⇒ Boolean
-
#expire(ttl = nil) ⇒ Object
Sets a timeout on key.
-
#hdel!(field) ⇒ Integer
Deletes a field from the hash stored at the Redis key.
- #hget(field) ⇒ Object
-
#hgetall ⇒ Object
(also: #all)
For parity with RedisType#hgetall.
- #hkeys ⇒ Object
- #hlen ⇒ Object (also: #hlength)
- #hmset ⇒ Object
-
#hset(field, value) ⇒ Object
The number of fields that were added to the hash.
- #hstrlen(field) ⇒ Object (also: #hstrlength)
- #hvals ⇒ Object
- #incr(field) ⇒ Object (also: #increment)
- #incrby(field, increment) ⇒ Object (also: #incrementby)
- #incrbyfloat(field, increment) ⇒ Object (also: #incrementbyfloat)
- #key?(field) ⇒ Boolean (also: #has_key?)
- #realttl ⇒ Object
- #redistype ⇒ Object
-
#rename(newkey) ⇒ Object
Parity with RedisType#rename.
Instance Method Details
#decr(field) ⇒ Object Also known as: decrement
114 115 116 |
# File 'lib/familia/horreum/commands.rb', line 114 def decr(field) redis.hdecr field end |
#decrby(field, decrement) ⇒ Object Also known as: decrementby
109 110 111 |
# File 'lib/familia/horreum/commands.rb', line 109 def decrby(field, decrement) redis.decrby rediskey(suffix), field, decrement end |
#exists? ⇒ Boolean
21 22 23 24 |
# File 'lib/familia/horreum/commands.rb', line 21 def exists? # Trace output comes from the class method self.class.exists? identifier, suffix end |
#expire(ttl = nil) ⇒ Object
Sets a timeout on key. After the timeout has expired, the key will automatically be deleted. Returns 1 if the timeout was set, 0 if key does not exist or the timeout could not be set.
30 31 32 33 34 |
# File 'lib/familia/horreum/commands.rb', line 30 def expire(ttl = nil) ttl ||= self.class.ttl Familia.trace :EXPIRE, redis, ttl, caller(1..1) if Familia.debug? redis.expire rediskey, ttl.to_i end |
#hdel!(field) ⇒ Integer
This method is destructive, as indicated by the bang (!).
Deletes a field from the hash stored at the Redis key.
46 47 48 49 |
# File 'lib/familia/horreum/commands.rb', line 46 def hdel!(field) Familia.trace :HDEL, redis, field, caller(1..1) if Familia.debug? redis.hdel rediskey, field end |
#hget(field) ⇒ Object
69 70 71 72 |
# File 'lib/familia/horreum/commands.rb', line 69 def hget(field) Familia.trace :HGET, redis, field, caller(1..1) if Familia.debug? redis.hget rediskey(suffix), field end |
#hgetall ⇒ Object Also known as: all
For parity with RedisType#hgetall
63 64 65 66 |
# File 'lib/familia/horreum/commands.rb', line 63 def hgetall Familia.trace :HGETALL, redis, redisuri, caller(1..1) if Familia.debug? redis.hgetall rediskey(suffix) end |
#hkeys ⇒ Object
85 86 87 88 |
# File 'lib/familia/horreum/commands.rb', line 85 def hkeys Familia.trace :HKEYS, redis, 'redisuri', caller(1..1) if Familia.debug? redis.hkeys rediskey(suffix) end |
#hlen ⇒ Object Also known as: hlength
119 120 121 |
# File 'lib/familia/horreum/commands.rb', line 119 def hlen redis.hlen rediskey(suffix) end |
#hmset ⇒ Object
81 82 83 |
# File 'lib/familia/horreum/commands.rb', line 81 def hmset redis.hmset rediskey(suffix), self.to_h end |
#hset(field, value) ⇒ Object
Returns The number of fields that were added to the hash. If the field already exists, this will return 0.
76 77 78 79 |
# File 'lib/familia/horreum/commands.rb', line 76 def hset(field, value) Familia.trace :HSET, redis, field, caller(1..1) if Familia.debug? redis.hset rediskey, field, value end |
#hstrlen(field) ⇒ Object Also known as: hstrlength
124 125 126 |
# File 'lib/familia/horreum/commands.rb', line 124 def hstrlen(field) redis.hstrlen rediskey(suffix), field end |
#hvals ⇒ Object
90 91 92 |
# File 'lib/familia/horreum/commands.rb', line 90 def hvals redis.hvals rediskey(suffix) end |
#incr(field) ⇒ Object Also known as: increment
94 95 96 |
# File 'lib/familia/horreum/commands.rb', line 94 def incr(field) redis.hincrby rediskey(suffix), field, 1 end |
#incrby(field, increment) ⇒ Object Also known as: incrementby
99 100 101 |
# File 'lib/familia/horreum/commands.rb', line 99 def incrby(field, increment) redis.hincrby rediskey(suffix), field, increment end |
#incrbyfloat(field, increment) ⇒ Object Also known as: incrementbyfloat
104 105 106 |
# File 'lib/familia/horreum/commands.rb', line 104 def incrbyfloat(field, increment) redis.hincrbyfloat rediskey(suffix), field, increment end |
#key?(field) ⇒ Boolean Also known as: has_key?
129 130 131 |
# File 'lib/familia/horreum/commands.rb', line 129 def key?(field) redis.hexists rediskey(suffix), field end |
#realttl ⇒ Object
36 37 38 39 |
# File 'lib/familia/horreum/commands.rb', line 36 def realttl Familia.trace :REALTTL, redis, redisuri, caller(1..1) if Familia.debug? redis.ttl rediskey end |