Module: Widescreen
- Extended by:
- Widescreen
- Included in:
- Widescreen
- Defined in:
- lib/widescreen.rb,
lib/widescreen/stat.rb,
lib/widescreen/metric.rb,
lib/widescreen/version.rb,
lib/widescreen/dashboard.rb
Defined Under Namespace
Classes: Dashboard, Metric, Stat
Constant Summary collapse
- SEPARATOR =
":"
- VERSION =
"0.1.1"
Instance Method Summary collapse
-
#redis ⇒ Object
Returns the current Redis connection.
-
#redis=(server) ⇒ Object
Accepts: 1.
- #redis_id ⇒ Object
Instance Method Details
#redis ⇒ Object
Returns the current Redis connection. If none has been created, will create a new one.
44 45 46 47 48 |
# File 'lib/widescreen.rb', line 44 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 '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`.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/widescreen.rb', line 21 def redis=(server) case server when String 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 ||= :resque @redis = Redis::Namespace.new(namespace, :redis => redis) when Redis::Namespace @redis = server else @redis = Redis::Namespace.new(:resque, :redis => server) end end |
#redis_id ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/widescreen.rb', line 50 def redis_id # support 1.x versions of redis-rb if redis.respond_to?(:server) redis.server else redis.client.id end end |