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

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

Returns:

  • (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

Note:

This method is destructive, as indicated by the bang (!).

Deletes a field from the hash stored at the Redis key.

Parameters:

  • field (String)

    The field to delete from the hash.

Returns:

  • (Integer)

    The number of fields that were removed from the hash (0 or 1).



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

#hgetallObject 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

#hkeysObject



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

#hlenObject Also known as: hlength



119
120
121
# File 'lib/familia/horreum/commands.rb', line 119

def hlen
  redis.hlen rediskey(suffix)
end

#hmsetObject



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.

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

#hvalsObject



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?

Returns:

  • (Boolean)


129
130
131
# File 'lib/familia/horreum/commands.rb', line 129

def key?(field)
  redis.hexists rediskey(suffix), field
end

#realttlObject



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

#redistypeObject



51
52
53
54
# File 'lib/familia/horreum/commands.rb', line 51

def redistype
  Familia.trace :REDISTYPE, redis, redisuri, caller(1..1) if Familia.debug?
  redis.type rediskey(suffix)
end

#rename(newkey) ⇒ Object

Parity with RedisType#rename



57
58
59
60
# File 'lib/familia/horreum/commands.rb', line 57

def rename(newkey)
  Familia.trace :RENAME, redis, "#{rediskey} -> #{newkey}", caller(1..1) if Familia.debug?
  redis.rename rediskey, newkey
end