Module: RedisRedirect

Extended by:
RedisRedirect
Included in:
RedisRedirect
Defined in:
lib/redis-redirect.rb,
lib/redis-redirect/errors.rb,
lib/redis-redirect/routes.rb,
lib/redis-redirect/version.rb,
lib/redis-redirect/persistence.rb

Defined Under Namespace

Modules: Persistence Classes: RecordNotDestroyed, RecordNotSaved, RedisRedirectError, Routes

Constant Summary collapse

VERSION =
"0.2.0"

Instance Method Summary collapse

Instance Method Details

#redisObject

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



41
42
43
44
45
# File 'lib/redis-redirect.rb', line 41

def redis
  return @redis if @redis
  self.redis = Redis.respond_to?(:connect) ? Redis.connect(:thread_safe => true) : "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`.


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/redis-redirect.rb', line 18

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 ||= :redis_redirect

    @redis = Redis::Namespace.new(namespace, :redis => redis)
  when Redis::Namespace
    @redis = server
  else
    @redis = Redis::Namespace.new(:redis_redirect, :redis => server)
  end
end