Module: Stats::Helpers

Included in:
Stats
Defined in:
lib/stats/helpers.rb

Instance Method Summary collapse

Instance Method Details

#redisObject

Returns the current Redis connection. A default connection will be made if one doesn’t yet exist.



17
18
19
20
21
# File 'lib/stats/helpers.rb', line 17

def redis
  return @redis if @redis
  self.redis = 'localhost:6379'
  self.redis
end

#redis=(server) ⇒ Object

Sets the Redis server with the specified ‘hostname:port’ string or Redis object.



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

def redis=(server)
  case server
  when String
    host, port, db = server.split(':')
    @redis = Redis.new(:host => host, :port => port, :db => db, :thread_safe => true)
  else
    @redis = server
  end
end