Module: Resolver

Extended by:
Resolver
Included in:
Resolver
Defined in:
lib/resolver.rb,
lib/resolver/key.rb,
lib/resolver/version.rb

Defined Under Namespace

Modules: Key

Constant Summary collapse

VERSION =
"0.1.2"

Instance Method Summary collapse

Instance Method Details

#redisObject

Returns the current Redis connection. If none has been created, will create a new one.



38
39
40
41
42
# File 'lib/resolver.rb', line 38

def redis
  return @redis if @redis
  self.redis = ENV['RESOLVER_REDIS_URL'] || ENV['REDIS_URL'] || '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`.


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/resolver.rb', line 17

def redis=(server)
  if server.respond_to? :split
    if server =~ /redis\:\/\//
      redis = Redis.connect(:url => server)
    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 ||= :resolver
    @redis = Redis::Namespace.new(namespace, :redis => redis)
  elsif server.respond_to? :namespace=
    @redis = server
  else
    @redis = Redis::Namespace.new(:resolver, :redis => server)
  end
end