Module: SimpleRedis
- Defined in:
- lib/simple_redis.rb,
lib/simple_redis/version.rb
Constant Summary collapse
- VERSION =
"0.2.0"- HOST =
"localhost"- PORT =
6379- DEFAULT_DB =
"0"
Class Attribute Summary collapse
-
.current_opts ⇒ Object
Returns the value of attribute current_opts.
-
.current_redis ⇒ Object
Returns the value of attribute current_redis.
-
.default_db ⇒ Object
Returns the value of attribute default_db.
-
.host ⇒ Object
Returns the value of attribute host.
-
.port ⇒ Object
Returns the value of attribute port.
Class Method Summary collapse
- .configuration {|_self| ... } ⇒ Object
- .delete_matched(key, opts = {}) ⇒ Object
-
.fetch(opts = {}) ⇒ Object
Set or Get cache from Redis, opts => db, key, value, block.
- .get(key, opts = {}) ⇒ Object
- .set(key, value, opts = {}) ⇒ Object
- .total_matches(key, opts = {}) ⇒ Object
Class Attribute Details
.current_opts ⇒ Object
Returns the value of attribute current_opts.
8 9 10 |
# File 'lib/simple_redis.rb', line 8 def current_opts @current_opts end |
.current_redis ⇒ Object
Returns the value of attribute current_redis.
9 10 11 |
# File 'lib/simple_redis.rb', line 9 def current_redis @current_redis end |
.default_db ⇒ Object
Returns the value of attribute default_db.
7 8 9 |
# File 'lib/simple_redis.rb', line 7 def default_db @default_db end |
.host ⇒ Object
Returns the value of attribute host.
5 6 7 |
# File 'lib/simple_redis.rb', line 5 def host @host end |
.port ⇒ Object
Returns the value of attribute port.
6 7 8 |
# File 'lib/simple_redis.rb', line 6 def port @port end |
Class Method Details
.configuration {|_self| ... } ⇒ Object
12 13 14 |
# File 'lib/simple_redis.rb', line 12 def self.configuration yield self end |
.delete_matched(key, opts = {}) ⇒ Object
41 42 43 44 |
# File 'lib/simple_redis.rb', line 41 def self.delete_matched(key, opts={}) redis = get_redis(opts) redis.del(*redis.keys(key)) rescue 0 end |
.fetch(opts = {}) ⇒ Object
Set or Get cache from Redis, opts => db, key, value, block
17 18 19 20 21 22 |
# File 'lib/simple_redis.rb', line 17 def self.fetch(opts={}) redis = get_redis(opts) result = redis.get opts[:key] result = cache(redis, opts[:key], block_given? ? yield.inspect : opts[:value].inspect) if result.nil? get_result(result) end |
.get(key, opts = {}) ⇒ Object
30 31 32 33 34 |
# File 'lib/simple_redis.rb', line 30 def self.get(key, opts={}) redis = get_redis(opts) result = redis.get key get_result(result) end |
.set(key, value, opts = {}) ⇒ Object
24 25 26 27 28 |
# File 'lib/simple_redis.rb', line 24 def self.set(key, value, opts={}) redis = get_redis(opts) result = cache(redis, key, value.inspect) get_result(result) end |
.total_matches(key, opts = {}) ⇒ Object
36 37 38 39 |
# File 'lib/simple_redis.rb', line 36 def self.total_matches(key, opts={}) redis = get_redis(opts) redis.keys(key).size end |