Class: SimpleRedisOrm::Entry
Class Method Summary
collapse
Instance Method Summary
collapse
read_by, read_hash, read_value
#deserialize_hash_value, #deserialize_value, #serialize_value
#exists, #exists?, #expire, #read, #read_hash, #read_subhash, #read_value, #set, #set_hash, #set_subhash, #ttl
Class Method Details
.create(id:, **attributes) ⇒ Object
20
21
22
|
# File 'lib/simple-redis-orm/entry.rb', line 20
def create(id:, **attributes)
new(id: id, **attributes).save
end
|
.find(id) ⇒ Object
24
25
26
27
28
29
|
# File 'lib/simple-redis-orm/entry.rb', line 24
def find(id)
value = read_by(id)
return if value.nil?
new(id: id, **value)
end
|
.new(id:, **attributes) ⇒ Object
15
16
17
18
|
# File 'lib/simple-redis-orm/entry.rb', line 15
def new(id:, **attributes)
attrs_with_defaults = fill_in_missing_keys(**attributes)
super(key: id, **attrs_with_defaults)
end
|
.redis ⇒ Object
31
32
33
|
# File 'lib/simple-redis-orm/entry.rb', line 31
def redis
@redis || raise(NotConnected, "#{name}.redis not set to a Redis.new connection pool")
end
|
.without_redis_key_prefix(id) ⇒ Object
39
40
41
42
43
|
# File 'lib/simple-redis-orm/entry.rb', line 39
def without_redis_key_prefix(id)
return if id.nil?
id.gsub(/^(.*):/, '')
end
|
Instance Method Details
#attributes ⇒ Object
57
58
59
|
# File 'lib/simple-redis-orm/entry.rb', line 57
def attributes
super.except(:key)
end
|
#id ⇒ Object
10
11
12
|
# File 'lib/simple-redis-orm/entry.rb', line 10
def id
self.class.without_redis_key_prefix(key)
end
|
#redis ⇒ Object
61
62
63
|
# File 'lib/simple-redis-orm/entry.rb', line 61
def redis
self.class.redis
end
|
#save ⇒ Object
65
66
67
68
69
|
# File 'lib/simple-redis-orm/entry.rb', line 65
def save
set_hash(attributes.except(:key))
self
end
|