Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Examples of usage:

{Horaci Cuevas}[http://github.com/horaci] <horaci@gmail.com>

{Robert R. Meyer}[http://github.com/Blue-Dog-Archolite] <Blue.Dog.Archolite@gmail.com>

== Quick overview

* Setup
Expand All @@ -23,7 +25,10 @@ Before using Similus, you need to setup the redis configuration. In rails this c

Similus.config do |config|
config.backend = :redis
config.redis_server = "localhost:6379"
config.redis_host = "localhost"
config.redis_port = "6379"
config.redis_username = "myredisuser"
config.redis_password = "Password"
config.redis_db = 8
end

Expand Down Expand Up @@ -73,4 +78,4 @@ Install the Similus gem:

Copyright (c) 2010 Horaci Cuevas

See LICENSES for details.
See LICENSES for details.
10 changes: 7 additions & 3 deletions lib/similus/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ def self.config
@config ||= Config.new
block_given? ? yield(@config) : @config
end

class Config
attr_accessor :backend
attr_accessor :redis_server
attr_accessor :redis_host
attr_accessor :redis_port
attr_accessor :redis_username
attr_accessor :redis_password
attr_accessor :redis_db
attr_accessor :logfile

def initialize #:nodoc:
self.backend = :redis
self.redis_server = "localhost:6379"
self.redis_host = "localhost"
self.redis_port = "6379"
self.redis_db = 9
self.logfile = STDOUT
end
Expand Down
7 changes: 4 additions & 3 deletions lib/similus/redis.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
module Similus
def self.redis
@redis ||= begin
host, port = config.redis_server.split(':')
::Redis.new(:host => host, :port => port, :db => config.redis_db)
::Redis.new(:host => config.redis_host, :port => config.redis_port,
:username => config.redis_username, :password => config.redis_password,
:thread_safe => true)
rescue Exception => e
config.logger.error "Error connecting redis server: #{e.message}"
nil
end
end

def self.clear_database!
@cache = {}
redis.flushdb
Expand Down