lib/ohm.rb in ohm-0.0.13 vs lib/ohm.rb in ohm-0.0.14
- old
+ new
@@ -4,37 +4,41 @@
module Ohm
# Provides access to the Redis database. This is shared accross all models and instances.
def redis
- @redis
+ Thread.current[:redis]
end
+ def redis=(connection)
+ Thread.current[:redis] = connection
+ end
+
# Connect to a redis database.
#
# @param options [Hash] options to create a message with.
# @option options [#to_s] :host ('127.0.0.1') Host of the redis database.
# @option options [#to_s] :port (6379) Port number.
# @option options [#to_s] :db (0) Database number.
# @option options [#to_s] :timeout (0) Database timeout in seconds.
# @example Connect to a database in port 6380.
# Ohm.connect(:port => 6380)
def connect(*options)
- @redis = Ohm::Redis.new(*options)
+ self.redis = Ohm::Redis.new(*options)
end
# Clear the database.
def flush
- @redis.flushdb
+ redis.flushdb
end
# Join the parameters with ":" to create a key.
def key(*args)
args.join(":")
end
- module_function :key, :connect, :flush, :redis
+ module_function :key, :connect, :flush, :redis, :redis=
module Attributes
class Collection
include Enumerable
@@ -488,10 +492,10 @@
db.set(key(att), value)
end
def read_locals(attrs)
attrs.map do |att|
- read_local(att)
+ send(att)
end
end
def read_remotes(attrs)
attrs.map do |att|