Module: Familia
- Includes:
- Gibbler::Complex
- Included in:
- Bone, Customer, Limiter, Session
- Defined in:
- lib/familia.rb,
lib/familia.rb,
lib/familia.rb,
lib/familia/tools.rb,
lib/familia/object.rb,
lib/familia/helpers.rb,
lib/familia/redisobject.rb
Defined Under Namespace
Modules: ClassMethods, Collector, InstanceMethods, Stamps, Status, Tools, VERSION
Classes: HashKey, List, NoIndex, NonUniqueKey, NotConnected, Problem, RedisObject, Set, SortedSet, String
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.apiversion(r = nil, &blk) ⇒ Object
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/familia.rb', line 114
def apiversion(r=nil, &blk)
if blk.nil?
@apiversion = r if r;
else
tmp = @apiversion
@apiversion = r
blk.call
@apiversion = tmp
end
@apiversion
end
|
.clients ⇒ Object
Returns the value of attribute clients.
36
37
38
|
# File 'lib/familia.rb', line 36
def clients
@clients
end
|
.debug ⇒ Object
Returns the value of attribute debug.
37
38
39
|
# File 'lib/familia.rb', line 37
def debug
@debug
end
|
.delim ⇒ Object
Returns the value of attribute delim.
37
38
39
|
# File 'lib/familia.rb', line 37
def delim
@delim
end
|
.dump_method ⇒ Object
Returns the value of attribute dump_method.
37
38
39
|
# File 'lib/familia.rb', line 37
def dump_method
@dump_method
end
|
.load_method ⇒ Object
Returns the value of attribute load_method.
37
38
39
|
# File 'lib/familia.rb', line 37
def load_method
@load_method
end
|
.logger ⇒ Object
Returns the value of attribute logger.
36
37
38
|
# File 'lib/familia.rb', line 36
def logger
@logger
end
|
.secret ⇒ Object
Returns the value of attribute secret.
37
38
39
|
# File 'lib/familia.rb', line 37
def secret
@secret
end
|
.uri ⇒ Object
Returns the value of attribute uri.
36
37
38
|
# File 'lib/familia.rb', line 36
def uri
@uri
end
|
Class Method Details
.classes(with_redis_objects = false) ⇒ Object
43
44
45
|
# File 'lib/familia.rb', line 43
def classes with_redis_objects=false
with_redis_objects ? [@classes, RedisObject.classes].flatten : @classes
end
|
.connect(uri = nil) ⇒ Object
85
86
87
88
89
90
91
92
|
# File 'lib/familia.rb', line 85
def connect(uri=nil)
uri &&= URI.parse uri if String === uri
uri ||= Familia.uri
conf = uri.conf
redis = Redis.new conf
Familia.trace :CONNECT, redis, conf.inspect, caller[0..3] if Familia.debug
@clients[uri.serverid] = redis
end
|
.connected?(uri = nil) ⇒ Boolean
99
100
101
102
|
# File 'lib/familia.rb', line 99
def connected?(uri=nil)
uri &&= URI.parse uri if String === uri
@clients.has_key?(uri.serverid)
end
|
.debug? ⇒ Boolean
39
|
# File 'lib/familia.rb', line 39
def debug?() @debug == true end
|
.default_suffix(a = nil) ⇒ Object
103
|
# File 'lib/familia.rb', line 103
def default_suffix(a=nil) @suffix = a if a; @suffix end
|
.default_suffix=(a) ⇒ Object
104
|
# File 'lib/familia.rb', line 104
def default_suffix=(a) @suffix = a end
|
.included(obj) ⇒ Object
150
151
152
153
154
155
156
|
# File 'lib/familia.rb', line 150
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
|
.index(r = nil) ⇒ Object
105
|
# File 'lib/familia.rb', line 105
def index(r=nil) @index = r if r; @index end
|
.index=(r) ⇒ Object
106
|
# File 'lib/familia.rb', line 106
def index=(r) @index = r; r end
|
.info(*msg) ⇒ Object
40
41
42
|
# File 'lib/familia.rb', line 40
def info *msg
STDERR.puts *msg
end
|
.join(*r) ⇒ Object
107
|
# File 'lib/familia.rb', line 107
def join(*r) r.join(Familia.delim) end
|
.ld(*msg) ⇒ Object
46
47
48
|
# File 'lib/familia.rb', line 46
def ld *msg
info *msg if debug?
end
|
.log(level, path) ⇒ Object
79
80
81
82
83
84
|
# File 'lib/familia.rb', line 79
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
|
.now(n = Time.now) ⇒ Object
125
126
127
|
# File 'lib/familia.rb', line 125
def now n=Time.now
n.utc.to_i
end
|
.qnow(quantum = 10.minutes, now = Familia.now) ⇒ Object
A quantized timestamp e.g. 12:32 -> 12:30
131
132
133
134
|
# File 'lib/familia.rb', line 131
def qnow quantum=10.minutes, now=Familia.now
rounded = now - (now % quantum)
Time.at(rounded).utc.to_i
end
|
.reconnect_all! ⇒ Object
93
94
95
96
97
98
|
# File 'lib/familia.rb', line 93
def reconnect_all!
Familia.classes.each do |klass|
klass.redis.client.reconnect
Familia.info "#{klass} ping: #{klass.redis.ping}" if debug?
end
end
|
.redis(uri = nil) ⇒ Object
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.
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/familia.rb', line 67
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
|
.rediskey(*args) ⇒ Object
109
110
111
112
113
|
# File 'lib/familia.rb', line 109
def rediskey *args
el = args.flatten.compact
el.unshift @apiversion unless @apiversion.nil?
el.join(Familia.delim)
end
|
.split(r) ⇒ Object
108
|
# File 'lib/familia.rb', line 108
def split(r) r.split(Familia.delim) end
|
.trace(label, redis_instance, ident, context = nil) ⇒ Object
49
50
51
52
53
54
55
56
57
|
# File 'lib/familia.rb', line 49
def trace label, redis_instance, ident, context=nil
return unless Familia.debug?
info "[%s] %s/%s" % [label, redis_instance.id, ident]
if context
context = [context].flatten
context.reject! { |line| line =~ /lib\/familia/ }
info " %s" % context[0..6].join("\n ")
end
end
|