Module: Afterburn::RedisConnection
- Included in:
- Afterburn
- Defined in:
- lib/afterburn/redis_connection.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.
32 33 34 35 36 |
# File 'lib/afterburn/redis_connection.rb', line 32 def redis return @redis if @redis self.redis = Redis.respond_to?(:connect) ? Redis.connect : "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. A Redis URL String 'redis://host:port'
4. An instance of `Redis`, `Redis::Client`, `Redis::DistRedis`
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/afterburn/redis_connection.rb', line 11 def redis=(server) case server when String if server =~ /redis\:\/\// redis = Redis.connect(:url => server, :thread_safe => true) else host, port, db = server.split(':') redis = Redis.new(:host => host, :port => port, :thread_safe => true, :db => db) end @redis = redis else @redis = server end @redis end |