# File lib/familia.rb, line 122 def apiversion(r=nil, &blk) if blk.nil? @apiversion = r if r; else tmp = @apiversion @apiversion = r blk.call @apiversion = tmp end @apiversion end
# File lib/familia.rb, line 42 def classes with_redis_objects=false with_redis_objects ? [@classes, RedisObject.classes].flatten : @classes end
# File lib/familia.rb, line 84 def connect(uri=nil) uri &&= URI.parse uri if String === uri uri ||= Familia.uri conf = uri.conf conf[:thread_safe] = "true" unless conf.has_key?(:thread_safe) conf[:thread_safe] = conf[:thread_safe].to_s == "true" conf[:logging] = conf[:logging].to_s == "true" if conf.has_key?(:logging) && conf[:logging].to_s == "true" require 'logger' require 'log4r' @logger ||= log :DEBUG, "./familia.log" conf[:logger] = Familia.logger end redis = Redis.new conf Familia.trace :CONNECT, redis, conf.inspect, caller[0..3] if Familia.debug @clients[uri.serverid] = redis end
# File lib/familia.rb, line 107 def connected?(uri=nil) uri &&= URI.parse uri if String === uri @clients.has_key?(uri.serverid) end
# File lib/familia.rb, line 111 def default_suffix(a=nil) @suffix = a if a; @suffix end
# File lib/familia.rb, line 112 def default_suffix=(a) @suffix = a end
# File lib/familia.rb, line 158 def self.included(obj) obj.send :include, Familia::InstanceMethods obj.send :include, Gibbler::Complex obj.extend Familia::ClassMethods obj.class_zset :instances, :class => obj, :reference => true Familia.classes << obj end
# File lib/familia.rb, line 113 def index(r=nil) @index = r if r; @index end
# File lib/familia.rb, line 115 def join(*r) r.join(Familia.delim) end
# File lib/familia.rb, line 78 def log(level, path) logger = Log4r::Logger.new('familia') logger.outputters = Log4r::FileOutputter.new 'familia', :filename => path logger.level = Log4r.const_get(level) logger end
# File lib/familia.rb, line 133 def now n=Time.now n.utc.to_i end
A quantized timestamp e.g. 12:32 -> 12:30
# File lib/familia.rb, line 139 def qnow quantum=10.minutes, now=Familia.now rounded = now - (now % quantum) Time.at(rounded).utc.to_i end
# File lib/familia.rb, line 101 def reconnect_all! Familia.classes.each do |klass| klass.redis.client.reconnect Familia.info "#{klass} ping: #{klass.redis.ping}" if debug? end end
A convenience method for returning the appropriate Redis connection. If uri is an Integer, we’ll treat it as a database number. If it’s a String, we’ll treat it as a full URI (e.g. redis://1.2.3.4/15). Otherwise we’ll return the default connection.
# File lib/familia.rb, line 66 def redis(uri=nil) if Integer === uri tmp = Familia.uri tmp.db = uri uri = tmp elsif String === uri uri &&= URI.parse uri end uri ||= Familia.uri connect(uri) unless @clients[uri.serverid] @clients[uri.serverid] end
# File lib/familia.rb, line 117 def rediskey *args el = args.flatten.compact el.unshift @apiversion unless @apiversion.nil? el.join(Familia.delim) end
# File lib/familia.rb, line 116 def split(r) r.split(Familia.delim) end
# File lib/familia.rb, line 48 def trace label, redis_client, ident, context=nil return unless Familia.debug? info "[%s] %s/%s" % [label, redis_client.uri, ident] if context context = [context].flatten context.reject! { |line| line =~ /lib\/familia/ } info " %s" % context[0..6].join("\n ") end end
Generated with the Darkfish Rdoc Generator 2.