Module: SimpleRedis

Defined in:
lib/simple_redis.rb,
lib/simple_redis/version.rb

Constant Summary collapse

VERSION =
"0.3.0"
HOST =
"localhost"
PORT =
6379
DEFAULT_DB =
"0"
NORMAL_DATA_TYPES =
[String, Fixnum, Integer, Float, NilClass, Symbol, Range]

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



39
40
41
42
# File 'lib/simple_redis.rb', line 39

def self.delete_matched(key, opts={})
  redis = get_redis(opts)
  redis.del(*redis.keys(key)) rescue 0
end

.fetch(opts = {}) ⇒ Object



16
17
18
19
20
# File 'lib/simple_redis.rb', line 16

def self.fetch(opts={})
  redis = get_redis(opts)
  result = redis.get opts[:key]
  get_result(result || cache(redis, opts[:key], block_given? ? yield : opts[:value]))
end

.get(key, opts = {}) ⇒ Object



28
29
30
31
32
# File 'lib/simple_redis.rb', line 28

def self.get(key, opts={})
  redis = get_redis(opts)
  result = redis.get key
  get_result(result)
end

.set(key, value, opts = {}) ⇒ Object



22
23
24
25
26
# File 'lib/simple_redis.rb', line 22

def self.set(key, value, opts={})
  redis = get_redis(opts)
  result = cache(redis, key, value)
  get_result(result)
end

.total_matches(key, opts = {}) ⇒ Object



34
35
36
37
# File 'lib/simple_redis.rb', line 34

def self.total_matches(key, opts={})
  redis = get_redis(opts)
  redis.keys(key).size
end