Module: Lunar::Connection

Included in:
Lunar
Defined in:
lib/lunar/connection.rb

Overview

This is actually taken from Ohm (ohm.keyvalue.org). The Lunar module extends this to make the API easier to use.

Lunar.connect(:host => "127.0.0.1", :port => "6380")
Lunar.redis
# basically returns Redis.new(:host => "127.0.0.1", :port => "6380")

# If you don't provide any connection, it assumes you are referring
# to the default redis host / port (127.0.0.1 on port 6379)
Lunar.redis

Instance Method Summary collapse

Instance Method Details

#connect(*options) ⇒ Object

Connect to a redis database.

Examples:

Connect to a database in port 6380.

Lunar.connect(:port => 6380)

Parameters:

  • options (Hash)

    options to create a message with.

Options Hash (*options):

  • :host (#to_s) — default: '127.0.0.1'

    Host of the redis database.

  • :port (#to_s) — default: 6379

    Port number.

  • :db (#to_s) — default: 0

    Database number.

  • :timeout (#to_s) — default: 0

    Database timeout in seconds.



23
24
25
26
# File 'lib/lunar/connection.rb', line 23

def connect(*options)
  self.redis = nil
  @options = options
end

#redisRedis

models and instances.

Returns:

  • (Redis)

    an instance of Redis



32
33
34
# File 'lib/lunar/connection.rb', line 32

def redis
  threaded[:redis] ||= connection(*options)
end

#redis=(connection) ⇒ Object

Parameters:

  • connection (Redis)

    the redis connection



38
39
40
# File 'lib/lunar/connection.rb', line 38

def redis=(connection)
  threaded[:redis] = connection
end