Module: Synth

Extended by:
Synth
Included in:
Synth
Defined in:
lib/synth.rb,
lib/synth/helpers.rb,
lib/synth/publish.rb,
lib/synth/version.rb,
lib/synth/rails/engine.rb

Defined Under Namespace

Modules: Helpers, Publish, Rails

Constant Summary collapse

VERSION =
"0.0.2"

Instance Method Summary collapse

Instance Method Details

#redisObject

Returns the Redis connection. If none exists, try creating one.



43
44
45
# File 'lib/synth.rb', line 43

def redis
  @redis ||= self.redis = Redis.respond_to?(:connect) ? Redis.connect : 'localhost:6379'
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`.


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/synth.rb', line 20

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

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