Module: CustomRedis
- Defined in:
- lib/custom_redis.rb,
lib/custom_redis/version.rb
Constant Summary collapse
- VERSION =
"0.1.0"
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
-
#redis ⇒ Object
readonly
Returns the value of attribute redis.
Class Method Summary collapse
Instance Method Summary collapse
-
#delete(object, custom_key) ⇒ Object
It delete in Redis a key-value as { :“model:id:method1_method2_method3” => value }.
-
#eval(object, methods) ⇒ Object
It evals if a key-value exists in Redis Server, being inserted if It doesn’t exist It returns { “key” => “value” }.
-
#flush(pattern) ⇒ Object
It delete all Redis key-values which.
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
6 7 8 |
# File 'lib/custom_redis.rb', line 6 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
7 8 9 |
# File 'lib/custom_redis.rb', line 7 def port @port end |
#redis ⇒ Object (readonly)
Returns the value of attribute redis.
8 9 10 |
# File 'lib/custom_redis.rb', line 8 def redis @redis end |
Class Method Details
.new(host = 'localhost', port = 6379) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/custom_redis.rb', line 10 def self.new(host = 'localhost', port = 6379) @host = host @port = port $custom_redis = Redis.new(:host => @host, :port => @port) end |
Instance Method Details
#delete(object, custom_key) ⇒ Object
It delete in Redis a key-value as { :“model:id:method1_method2_method3” => value }
18 19 20 |
# File 'lib/custom_redis.rb', line 18 def delete(object, custom_key) $custom_redis.del(my_redis_key(object.class.to_s, object.id.to_s, custom_key.to_s)) end |
#eval(object, methods) ⇒ Object
It evals if a key-value exists in Redis Server, being inserted if It doesn’t exist It returns { “key” => “value” }
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/custom_redis.rb', line 32 def eval(object, methods) key = methods.join('_') if value = get(object, key) { key => value }.deep_symbolize_keys elsif methods.present? value = object.public_send(methods[0]) for i in 1..methods.size-1 value = value.public_send(methods[i]) end set( self, { key => value}) end end |
#flush(pattern) ⇒ Object
It delete all Redis key-values which
23 24 25 26 27 28 |
# File 'lib/custom_redis.rb', line 23 def flush(pattern) list = $custom_redis.keys(pattern) list.each do |element| $custom_redis.del(element) end end |