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



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

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.



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

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).



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

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

#hkeysObject



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

#hlenObject Also known as: hlength



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

def hlen
  redis.hlen rediskey(suffix)
end

#hmsetObject



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.

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

#hvalsObject



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?

Returns:

  • (Boolean)


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

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

#realttlObject



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

#redistypeObject



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

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



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

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