Module: Rolex
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/rolex.rb,
lib/rolex/version.rb
Overview
ROLEX - Redis backed roles
Constant Summary collapse
- SUFFIX =
ENV['RAILS_ENV'] || 'development'
- VERSION =
"0.0.4"
Class Method Summary collapse
-
.redis ⇒ Object
Returns the current Redis connection.
-
.redis=(server) ⇒ Object
Lifted directly from Split: github.com/andrew/split/blob/master/lib/split.rb#L12-L37.
Class Method Details
.redis ⇒ Object
Returns the current Redis connection. If none has been created, will create a new one.
40 41 42 43 44 |
# File 'lib/rolex.rb', line 40 def self.redis return @redis if @redis self.redis = 'localhost:6379' self.redis end |
.redis=(server) ⇒ Object
Lifted directly from Split: github.com/andrew/split/blob/master/lib/split.rb#L12-L37
Accepts:
1. A 'hostname:port' string
2. A 'hostname:port:db' string (to select the Redis db)
3. A 'hostname:port/namespace' string (to set the Redis namespace)
4. A redis URL string 'redis://host:port'
5. An instance of `Redis`, `Redis::Client`, `Redis::DistRedis`,
or `Redis::Namespace`.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rolex.rb', line 18 def self.redis=(server) if server.respond_to? :split if server["redis://"] redis = Redis.connect(:url => server, :thread_safe => true) else server, namespace = server.split('/', 2) host, port, db = server.split(':') redis = Redis.new(:host => host, :port => port, :thread_safe => true, :db => db) end namespace ||= :rolex @redis = Redis::Namespace.new(namespace, :redis => redis) elsif server.respond_to? :namespace= @redis = server else @redis = Redis::Namespace.new(:rolex, :redis => server) end end |