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



107
108
109
# File 'lib/familia/horreum/commands.rb', line 107

def decr(field)
  redis.hdecr field
end

#decrby(field, decrement) ⇒ Object Also known as: decrementby



102
103
104
# File 'lib/familia/horreum/commands.rb', line 102

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?
  ret = redis.exists rediskey
  ret.positive? # differs from redis API but I think it's okay bc `exists?` is a predicate method.
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
# File 'lib/familia/horreum/commands.rb', line 29

def expire(ttl = nil)
  ttl ||= self.class.ttl
  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).



43
44
45
# File 'lib/familia/horreum/commands.rb', line 43

def hdel!(field)
  redis.hdel rediskey, field
end

#hget(field) ⇒ Object



63
64
65
# File 'lib/familia/horreum/commands.rb', line 63

def hget(field)
  redis.hget rediskey(suffix), field
end

#hgetallObject Also known as: all

For parity with RedisType#hgetall



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

def hgetall
  Familia.trace :HGETALL, redis, redisuri, caller(1..1) if Familia.debug?
  redis.hgetall rediskey(suffix)
end

#hkeysObject



78
79
80
81
# File 'lib/familia/horreum/commands.rb', line 78

def hkeys
  Familia.trace :HKEYS, redis, 'redisuri', caller(1..1) if Familia.debug?
  redis.hkeys rediskey(suffix)
end

#hlenObject Also known as: hlength



112
113
114
# File 'lib/familia/horreum/commands.rb', line 112

def hlen
  redis.hlen rediskey(suffix)
end

#hmsetObject



74
75
76
# File 'lib/familia/horreum/commands.rb', line 74

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.



69
70
71
72
# File 'lib/familia/horreum/commands.rb', line 69

def hset(field, value)
  Familia.trace :HSET, redis, redisuri, caller(1..1) if Familia.debug?
  redis.hset rediskey, field, value
end

#hstrlen(field) ⇒ Object Also known as: hstrlength



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

def hstrlen(field)
  redis.hstrlen rediskey(suffix), field
end

#hvalsObject



83
84
85
# File 'lib/familia/horreum/commands.rb', line 83

def hvals
  redis.hvals rediskey(suffix)
end

#incr(field) ⇒ Object Also known as: increment



87
88
89
# File 'lib/familia/horreum/commands.rb', line 87

def incr(field)
  redis.hincrby rediskey(suffix), field, 1
end

#incrby(field, increment) ⇒ Object Also known as: incrementby



92
93
94
# File 'lib/familia/horreum/commands.rb', line 92

def incrby(field, increment)
  redis.hincrby rediskey(suffix), field, increment
end

#incrbyfloat(field, increment) ⇒ Object Also known as: incrementbyfloat



97
98
99
# File 'lib/familia/horreum/commands.rb', line 97

def incrbyfloat(field, increment)
  redis.hincrbyfloat rediskey(suffix), field, increment
end

#key?(field) ⇒ Boolean Also known as: has_key?

Returns:

  • (Boolean)


122
123
124
# File 'lib/familia/horreum/commands.rb', line 122

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

#realttlObject



34
35
36
# File 'lib/familia/horreum/commands.rb', line 34

def realttl
  redis.ttl rediskey
end

#redistypeObject



47
48
49
# File 'lib/familia/horreum/commands.rb', line 47

def redistype
  redis.type rediskey(suffix)
end

#rename(newkey) ⇒ Object

Parity with RedisType#rename



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

def rename(newkey)
  redis.rename rediskey, newkey
end