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
113 114 115 |
# File 'lib/familia/horreum/commands.rb', line 113 def decr(field) redis.hdecr field end |
#decrby(field, decrement) ⇒ Object Also known as: decrementby
108 109 110 |
# File 'lib/familia/horreum/commands.rb', line 108 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.
29 30 31 32 33 |
# File 'lib/familia/horreum/commands.rb', line 29 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.
45 46 47 48 |
# File 'lib/familia/horreum/commands.rb', line 45 def hdel!(field) Familia.trace :HDEL, redis, field, caller(1..1) if Familia.debug? redis.hdel rediskey, field end |
#hget(field) ⇒ Object
68 69 70 71 |
# File 'lib/familia/horreum/commands.rb', line 68 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
62 63 64 65 |
# File 'lib/familia/horreum/commands.rb', line 62 def hgetall Familia.trace :HGETALL, redis, redisuri, caller(1..1) if Familia.debug? redis.hgetall rediskey(suffix) end |
#hkeys ⇒ Object
84 85 86 87 |
# File 'lib/familia/horreum/commands.rb', line 84 def hkeys Familia.trace :HKEYS, redis, 'redisuri', caller(1..1) if Familia.debug? redis.hkeys rediskey(suffix) end |
#hlen ⇒ Object Also known as: hlength
118 119 120 |
# File 'lib/familia/horreum/commands.rb', line 118 def hlen redis.hlen rediskey(suffix) end |
#hmset ⇒ Object
80 81 82 |
# File 'lib/familia/horreum/commands.rb', line 80 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.
75 76 77 78 |
# File 'lib/familia/horreum/commands.rb', line 75 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
123 124 125 |
# File 'lib/familia/horreum/commands.rb', line 123 def hstrlen(field) redis.hstrlen rediskey(suffix), field end |
#hvals ⇒ Object
89 90 91 |
# File 'lib/familia/horreum/commands.rb', line 89 def hvals redis.hvals rediskey(suffix) end |
#incr(field) ⇒ Object Also known as: increment
93 94 95 |
# File 'lib/familia/horreum/commands.rb', line 93 def incr(field) redis.hincrby rediskey(suffix), field, 1 end |
#incrby(field, increment) ⇒ Object Also known as: incrementby
98 99 100 |
# File 'lib/familia/horreum/commands.rb', line 98 def incrby(field, increment) redis.hincrby rediskey(suffix), field, increment end |
#incrbyfloat(field, increment) ⇒ Object Also known as: incrementbyfloat
103 104 105 |
# File 'lib/familia/horreum/commands.rb', line 103 def incrbyfloat(field, increment) redis.hincrbyfloat rediskey(suffix), field, increment end |
#key?(field) ⇒ Boolean Also known as: has_key?
128 129 130 |
# File 'lib/familia/horreum/commands.rb', line 128 def key?(field) redis.hexists rediskey(suffix), field end |
#realttl ⇒ Object
35 36 37 38 |
# File 'lib/familia/horreum/commands.rb', line 35 def realttl Familia.trace :REALTTL, redis, redisuri, caller(1..1) if Familia.debug? redis.ttl rediskey end |