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

Class Method Summary collapse

Class Attribute Details

.current_optsObject

Returns the value of attribute current_opts.



8
9
10
# File 'lib/simple_redis.rb', line 8

def current_opts
  @current_opts
end

.current_redisObject

Returns the value of attribute current_redis.



9
10
11
# File 'lib/simple_redis.rb', line 9

def current_redis
  @current_redis
end

.default_dbObject

Returns the value of attribute default_db.



7
8
9
# File 'lib/simple_redis.rb', line 7

def default_db
  @default_db
end

.hostObject

Returns the value of attribute host.



5
6
7
# File 'lib/simple_redis.rb', line 5

def host
  @host
end

.portObject

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

Yields:

  • (_self)

Yield Parameters:

  • _self (SimpleRedis)

    the object that the method was called on



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