Class: RediConn::RedisProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/rediconn/redis_proxy.rb

Overview

Mainly intended for console use

Instance Method Summary collapse

Constructor Details

#initialize(&factory) ⇒ RedisProxy

Returns a new instance of RedisProxy.



4
5
6
# File 'lib/rediconn/redis_proxy.rb', line 4

def initialize(&factory)
  @factory = factory
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *arguments, &block) ⇒ Object



41
42
43
44
45
# File 'lib/rediconn/redis_proxy.rb', line 41

def method_missing(method_name, *arguments, &block)
  @factory.call do |r|
    r.send(method_name, *arguments, &block)
  end
end

Instance Method Details

#multi(*args, &block) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/rediconn/redis_proxy.rb', line 8

def multi(*args, &block)
  @factory.call do |r|
    r.multi(*args) do |r|
      block.call(r)
    end
  end
end

#pipelined(*args, &block) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/rediconn/redis_proxy.rb', line 16

def pipelined(*args, &block)
  @factory.call do |r|
    r.pipelined(*args) do |r2|
      block.call(r2 || r)
    end
  end
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/rediconn/redis_proxy.rb', line 47

def respond_to_missing?(method_name, include_private = false)
  super || Redis.method_defined?(method_name)
end

#uget(key) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rediconn/redis_proxy.rb', line 24

def uget(key)
  @factory.call do |r|
    case r.type(key)
    when 'string'
      r.get(key)
    when 'list'
      r.lrange(key, 0, -1)
    when 'hash'
      r.hgetall(key)
    when 'set'
      r.smembers(key)
    when 'zset'
      r.zrange(key, 0, -1)
    end
  end
end