familia 0.6.8 → 0.6.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,12 @@
1
1
  FAMILIA, CHANGES
2
2
 
3
+ #### 0.6.9 (2011-01-09) ###############################
4
+
5
+ * ADDED: RedisObject#cache
6
+ * ADDED: RedisObject#echo
7
+ # ADDED: Familia.logger (new option: :logger)
8
+
9
+
3
10
  #### 0.6.8 (2011-01-08) ###############################
4
11
 
5
12
  * CHANGE: RedisObject#members calls compact to remove nils
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :MAJOR: 0
3
3
  :MINOR: 6
4
- :PATCH: 8
4
+ :PATCH: 9
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{familia}
8
- s.version = "0.6.8"
8
+ s.version = "0.6.9"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Delano Mandelbaum"]
12
- s.date = %q{2011-01-08}
12
+ s.date = %q{2011-01-10}
13
13
  s.description = %q{Organize and store ruby objects in Redis}
14
14
  s.email = %q{delano@solutious.com}
15
15
  s.extra_rdoc_files = [
@@ -32,7 +32,7 @@ module Familia
32
32
  @dump_method = :to_json
33
33
  @load_method = :from_json
34
34
  class << self
35
- attr_reader :clients, :uri
35
+ attr_reader :clients, :uri, :logger
36
36
  attr_accessor :debug, :secret, :delim, :dump_method, :load_method
37
37
  attr_writer :apiversion
38
38
  def debug?() @debug == true end
@@ -71,14 +71,27 @@ module Familia
71
71
  connect(uri) unless @clients[uri.serverid]
72
72
  @clients[uri.serverid]
73
73
  end
74
+ def log(level, path)
75
+ logger = Log4r::Logger.new('familia')
76
+ logger.outputters = Log4r::FileOutputter.new 'familia', :filename => path
77
+ logger.level = Log4r.const_get(level)
78
+ logger
79
+ end
74
80
  def connect(uri=nil)
75
81
  uri &&= URI.parse uri if String === uri
76
82
  uri ||= Familia.uri
77
83
  conf = uri.conf
78
- conf[:thread_safe] = true
79
- client = Redis.new conf
80
- Familia.trace :CONNECT, client, conf.inspect, caller[0..3] if Familia.debug
81
- @clients[uri.serverid] = client
84
+ conf[:thread_safe] = true unless conf.has_key?(:thread_safe)
85
+ if conf.has_key?(:logging) && conf[:logging].to_s == "true"
86
+ require 'logger'
87
+ require 'log4r'
88
+ @logger ||= log :DEBUG, "./familia.log"
89
+ conf[:logger] = Familia.logger
90
+ end
91
+ redis = Redis.new conf
92
+ p redis.client.logger
93
+ Familia.trace :CONNECT, redis, conf.inspect, caller[0..3] if Familia.debug
94
+ @clients[uri.serverid] = redis
82
95
  end
83
96
  def reconnect_all!
84
97
  Familia.classes.each do |klass|
@@ -48,6 +48,12 @@ module Familia
48
48
 
49
49
  attr_reader :name, :parent
50
50
  attr_writer :redis
51
+
52
+ # RedisObject instances are frozen. `cache` is a hash
53
+ # for you to store values retreived from Redis. This is
54
+ # not used anywhere by default, but you're encouraged
55
+ # to use it in your specific scenarios.
56
+ attr_reader :cache
51
57
 
52
58
  # +name+: If parent is set, this will be used as the suffix
53
59
  # for rediskey. Otherwise this becomes the value of the key.
@@ -92,9 +98,18 @@ module Familia
92
98
  @parent = @opts.delete(:parent)
93
99
  @ttl = @opts.delete(:ttl)
94
100
  @redis ||= @opts.delete(:redis)
101
+ @cache = {}
95
102
  init if respond_to? :init
96
103
  end
97
104
 
105
+ def clear_cache
106
+ @cache.clear
107
+ end
108
+
109
+ def echo meth, trace
110
+ redis.echo "[#{self.class}\##{meth}] #{trace} (#{@opts[:class]}\##{name})"
111
+ end
112
+
98
113
  def redis
99
114
  return @redis if @redis
100
115
  parent? ? parent.redis : Familia.redis(db)
@@ -216,7 +231,7 @@ module Familia
216
231
  end
217
232
  end
218
233
  if ret.nil?
219
- Familia.info "[#{self.class}\#to_redis] nil returned for #{@opts[:class]}\##{name}"
234
+ Familia.ld "[#{self.class}\#to_redis] nil returned for #{@opts[:class]}\##{name}"
220
235
  end
221
236
  ret
222
237
  end
@@ -248,7 +263,7 @@ module Familia
248
263
  end
249
264
  end
250
265
  if ret.nil?
251
- Familia.info "[#{self.class}\#from_redis] nil returned for #{@opts[:class]}\##{name}"
266
+ Familia.ld "[#{self.class}\#from_redis] nil returned for #{@opts[:class]}\##{name}"
252
267
  end
253
268
  ret
254
269
  end
@@ -267,6 +282,7 @@ module Familia
267
282
  end
268
283
 
269
284
  def push *values
285
+ echo :push, caller[0] if Familia.debug
270
286
  values.flatten.compact.each { |v| redis.rpush rediskey, to_redis(v) }
271
287
  redis.ltrim rediskey, -@opts[:maxlength], -1 if @opts[:maxlength]
272
288
  self
@@ -315,7 +331,12 @@ module Familia
315
331
  alias_method :del, :delete
316
332
 
317
333
  def range sidx=0, eidx=-1
318
- redis.lrange(rediskey, sidx, eidx).collect { |v| from_redis(v) }.compact
334
+ # TODO: Use mget here and everywhere like it.
335
+ #if @opts[:reference] == true
336
+ # redis.lrange(rediskey, sidx, eidx)
337
+ #else
338
+ redis.lrange(rediskey, sidx, eidx).collect { |v| from_redis(v) }.compact
339
+ #end
319
340
  end
320
341
 
321
342
  def rangeraw sidx=0, eidx=-1
@@ -323,6 +344,7 @@ module Familia
323
344
  end
324
345
 
325
346
  def members count=-1
347
+ echo :members, caller[0] if Familia.debug
326
348
  count -= 1 if count > 0
327
349
  range 0, count
328
350
  end
@@ -428,6 +450,7 @@ module Familia
428
450
  end
429
451
 
430
452
  def members
453
+ echo :members, caller[0] if Familia.debug
431
454
  redis.smembers(rediskey).collect { |v| from_redis(v) }.compact
432
455
  end
433
456
  alias_method :all, :members
@@ -621,10 +644,12 @@ module Familia
621
644
  end
622
645
 
623
646
  def range sidx, eidx, opts={}
647
+ echo :range, caller[0] if Familia.debug
624
648
  rangeraw(sidx, eidx, opts).collect { |v| from_redis(v) }.compact
625
649
  end
626
650
 
627
651
  def revrange sidx, eidx, opts={}
652
+ echo :revrange, caller[0] if Familia.debug
628
653
  revrangeraw(sidx, eidx, opts).collect { |v| from_redis(v) }.compact
629
654
  end
630
655
 
@@ -640,10 +665,12 @@ module Familia
640
665
 
641
666
  # e.g. obj.metrics.rangebyscore (now-12.hours), now, :limit => [0, 10]
642
667
  def rangebyscore sscore, escore, opts={}
668
+ echo :rangebyscore, caller[0] if Familia.debug
643
669
  rangebyscoreraw(sscore, escore, opts).collect { |v| from_redis( v) }.compact
644
670
  end
645
671
 
646
672
  def rangebyscoreraw sscore, escore, opts={}
673
+ echo :rangebyscoreraw, caller[0] if Familia.debug
647
674
  opts[:with_scores] = true if opts[:withscores]
648
675
  redis.zrangebyscore(rediskey, sscore, escore, opts)
649
676
  end
@@ -797,6 +824,7 @@ module Familia
797
824
  end
798
825
 
799
826
  def value
827
+ echo :value, caller[0] if Familia.debug
800
828
  redis.setnx rediskey, @opts[:default] if @opts[:default]
801
829
  from_redis redis.get(rediskey)
802
830
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: familia
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 8
10
- version: 0.6.8
9
+ - 9
10
+ version: 0.6.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - Delano Mandelbaum
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-08 00:00:00 -05:00
18
+ date: 2011-01-10 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency