Class: RedisConnection

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

Constant Summary collapse

@@redis_connections =
{}

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ RedisConnection

Returns a new instance of RedisConnection.



5
6
7
8
9
10
11
12
# File 'lib/redis_connection.rb', line 5

def initialize(options={})
  key = options.keys.sort.map{|k| "#{k}:#{options[k]}"}.join(",")
  unless @@redis_connections.has_key?(key)
    @@redis_connections[key] = Redis.new(options)
  end
  @current_connection = @@redis_connections[key]
  @current_connection
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/redis_connection.rb', line 14

def method_missing(m, *args, &block)
  if @current_connection.respond_to?(m)
    @current_connection.send(m, *args)
  else
    super
  end
end