Module: SimpleRedisOrm::Helpers::CoreCommands
- Includes:
- Serializer
- Included in:
- Entry
- Defined in:
- lib/simple-redis-orm/helpers/core_commands.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary
collapse
Methods included from Serializer
#deserialize_hash_value, #deserialize_value, #serialize_value
Instance Method Details
#exists ⇒ Object
rubocop:enable Naming/AccessorMethodName
66
67
68
|
# File 'lib/simple-redis-orm/helpers/core_commands.rb', line 66
def exists
redis.exists key
end
|
#exists? ⇒ Boolean
70
71
72
|
# File 'lib/simple-redis-orm/helpers/core_commands.rb', line 70
def exists?
redis.exists? key
end
|
#expire(seconds) ⇒ Object
74
75
76
|
# File 'lib/simple-redis-orm/helpers/core_commands.rb', line 74
def expire(seconds)
redis.expire key, seconds
end
|
#read ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/simple-redis-orm/helpers/core_commands.rb', line 30
def read
type = redis.type key
return if type.nil?
return read_hash if type == 'hash'
read_value
end
|
#read_hash ⇒ Object
39
40
41
42
43
|
# File 'lib/simple-redis-orm/helpers/core_commands.rb', line 39
def read_hash
value = redis.hgetall(key)
deserialize_value(value)
end
|
#read_subhash(field) ⇒ Object
82
83
84
85
86
87
|
# File 'lib/simple-redis-orm/helpers/core_commands.rb', line 82
def read_subhash(field)
value = redis.hget(key, field)
return if value.nil?
deserialize_value(value)
end
|
#read_value ⇒ Object
45
46
47
48
|
# File 'lib/simple-redis-orm/helpers/core_commands.rb', line 45
def read_value
value = redis.get(key)
deserialize_value(value)
end
|
#set(value) ⇒ Object
50
51
52
53
54
55
|
# File 'lib/simple-redis-orm/helpers/core_commands.rb', line 50
def set(value)
return set_hash(value) if value.is_a?(Hash)
redis.set key, serialize_value(value)
nil
end
|
#set_hash(hash) ⇒ Object
rubocop:disable Naming/AccessorMethodName
58
59
60
61
62
63
|
# File 'lib/simple-redis-orm/helpers/core_commands.rb', line 58
def set_hash(hash)
raise ArgumentError, "'hash_value' must be a hash, found type: #{hash_value.class.name}" unless hash.is_a?(Hash)
hash.each_pair { |sub_key, value| set_subhash(sub_key, value) }
nil
end
|
#set_subhash(field, value) ⇒ Object
89
90
91
92
93
|
# File 'lib/simple-redis-orm/helpers/core_commands.rb', line 89
def set_subhash(field, value)
redis.hset(key, field, serialize_value(value))
nil
end
|
#ttl ⇒ Object
78
79
80
|
# File 'lib/simple-redis-orm/helpers/core_commands.rb', line 78
def ttl
redis.ttl(key)
end
|