Class: Reconfig::RedisClient
- Inherits:
-
Object
- Object
- Reconfig::RedisClient
show all
- Defined in:
- lib/reconfig/redis_client.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
47
48
49
50
51
52
|
# File 'lib/reconfig/redis_client.rb', line 47
def method_missing(method, *args, &block)
if connection.respond_to?(method)
return connection.send(method, *args, &block)
end
super
end
|
Instance Method Details
#fetch_by_type(key, stored_type) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/reconfig/redis_client.rb', line 5
def fetch_by_type(key, stored_type)
case stored_type
when type_mapper.string
connection.get(key)
when type_mapper.integer
connection.get(key).to_i
when type_mapper.float
connection.get(key).to_f
when type_mapper.hash
connection.hgetall(key)
when type_mapper.list
connection.lrange(key, 0, -1)
when type_mapper.set
connection.smembers(key)
else
raise UnknownTypeException.new("#{stored_type} is not a valid type.")
end
end
|
#respond_to?(method) ⇒ Boolean
43
44
45
|
# File 'lib/reconfig/redis_client.rb', line 43
def respond_to?(method)
connection.respond_to?(method) || super
end
|
#set_by_type(key, value) ⇒ Object
Overwrites associated value
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/reconfig/redis_client.rb', line 25
def set_by_type(key, value)
case type_mapper.stored_type(value)
when type_mapper.string, type_mapper.integer, type_mapper.float
connection.set(key, value)
when type_mapper.hash
connection.del key
connection.hmset(key, *value.to_a.flatten)
when type_mapper.list
connection.del key
connection.rpush key, *value
when type_mapper.set
connection.del key
connection.sadd key, *value
else
raise UnknownTypeException.new("Unable to store type #{value.class.name}.")
end
end
|