Module: Rediline::Redis
- Included in:
- Rediline
- Defined in:
- lib/rediline/redis.rb
Instance Method Summary collapse
-
#redis ⇒ Object
Returns the current Redis connection.
-
#redis=(server) ⇒ Object
Accepts: 1.
Instance Method Details
#redis ⇒ Object
Returns the current Redis connection. If none has been created, will create a new one.
29 30 31 32 33 |
# File 'lib/rediline/redis.rb', line 29 def redis return @redis if @redis self.redis = 'localhost:6379' self.redis end |
#redis=(server) ⇒ Object
Accepts:
1. A 'hostname:port' string
2. A 'hostname:port:db' string (to select the Redis db)
3. An instance of `Redis`, `Redis::Client`, or `Redis::Namespace`.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rediline/redis.rb', line 9 def redis=(server) case server when String host, port, db = server.split(':') redis = ::Redis.new(:host => host, :port => port, :thread_safe => true, :db => db) @redis = ::Redis::Namespace.new(:rediline, :redis => redis) when ::Redis, ::Redis::Client @redis = ::Redis::Namespace.new(:rediline, :redis => server) when ::Redis::Namespace @redis = server when nil @redis = nil else raise "I don't know what to do with #{server.inspect}" end end |