familia 0.6.10 → 0.7.0

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.7.0 (2011-03-04) ###############################
4
+
5
+ * CHANGE: Use RedisObject#multi_from_redis when possible (uses mget command)
6
+ * CHANGE: No need to check if a key exists before getting it. It will be nil anyway.
7
+ * ADDED: Set#randomraw
8
+
9
+
3
10
  #### 0.6.10 (2011-01-08) ###############################
4
11
 
5
12
  * FIXED: RedisObject#db does not set @db
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :MAJOR: 0
3
- :MINOR: 6
4
- :PATCH: 10
3
+ :MINOR: 7
4
+ :PATCH: 0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{familia}
8
- s.version = "0.6.10"
8
+ s.version = "0.7.0"
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-02-08}
12
+ s.date = %q{2011-03-04}
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 = [
@@ -44,11 +44,10 @@ Gem::Specification.new do |s|
44
44
  s.rdoc_options = ["--charset=UTF-8"]
45
45
  s.require_paths = ["lib"]
46
46
  s.rubyforge_project = %q{familia}
47
- s.rubygems_version = %q{1.3.7}
47
+ s.rubygems_version = %q{1.5.2}
48
48
  s.summary = %q{Organize and store ruby objects in Redis}
49
49
 
50
50
  if s.respond_to? :specification_version then
51
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
52
51
  s.specification_version = 3
53
52
 
54
53
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
@@ -47,8 +47,12 @@ module Familia
47
47
  end
48
48
  def trace label, redis_client, ident, context=nil
49
49
  return unless Familia.debug?
50
- info "%s (%d:%s): %s" % [label, Thread.current.object_id, redis_client.object_id, ident]
51
- info " +-> %s" % [context].flatten[0..3].join("\n ") if context
50
+ info "[%s] %s/%s" % [label, redis_client.uri, ident]
51
+ if context
52
+ context = [context].flatten
53
+ context.reject! { |line| line =~ /lib\/familia/ }
54
+ info " %s" % context[0..6].join("\n ")
55
+ end
52
56
  end
53
57
  def uri= v
54
58
  v = URI.parse v unless URI === v
@@ -249,15 +249,15 @@ module Familia
249
249
  obj
250
250
  end
251
251
  def from_key objkey
252
- raise ArgumentError, "Null key" if objkey.to_s.empty?
253
- Familia.trace :LOAD, redis, "#{self.uri}/#{objkey}", caller if Familia.debug?
252
+ raise ArgumentError, "Empty key" if objkey.to_s.empty?
253
+ Familia.trace :LOAD, Familia.redis(self.uri), objkey, caller if Familia.debug?
254
254
  obj = Familia::String.new objkey, :class => self
255
- obj.exists? ? obj.value : nil
255
+ obj.value
256
256
  end
257
257
  def from_redis idx, suffix=:object
258
258
  return nil if idx.to_s.empty?
259
259
  objkey = rediskey idx, suffix
260
- Familia.trace :FROMREDIS, Familia.redis(self.uri), objkey, caller.first if Familia.debug?
260
+ #Familia.trace :FROMREDIS, Familia.redis(self.uri), objkey, caller.first if Familia.debug?
261
261
  me = from_key objkey
262
262
  me
263
263
  end
@@ -265,12 +265,12 @@ module Familia
265
265
  return false if idx.to_s.empty?
266
266
  objkey = rediskey idx, suffix
267
267
  ret = Familia.redis(self.uri).exists objkey
268
- Familia.trace :EXISTS, Familia.redis(self.uri), "#{rediskey(idx, suffix)} #{ret}", caller.first if Familia.debug?
268
+ Familia.trace :EXISTS, Familia.redis(self.uri), "#{rediskey(idx, suffix)} #{ret}", caller if Familia.debug?
269
269
  ret
270
270
  end
271
271
  def destroy! idx, suffix=:object
272
272
  ret = Familia.redis(self.uri).del rediskey(idx, suffix)
273
- Familia.trace :DELETED, Familia.redis(self.uri), "#{rediskey(idx, suffix)}: #{ret}", caller.first if Familia.debug?
273
+ Familia.trace :DELETED, Familia.redis(self.uri), "#{rediskey(idx, suffix)}: #{ret}", caller if Familia.debug?
274
274
  ret
275
275
  end
276
276
  def find suffix='*'
@@ -107,7 +107,7 @@ module Familia
107
107
  end
108
108
 
109
109
  def echo meth, trace
110
- redis.echo "[#{self.class}\##{meth}] #{trace} (#{@opts[:class]}\##{name})"
110
+ redis.echo "[#{self.class}\##{meth}] #{trace} (#{@opts[:class]}\#)"
111
111
  end
112
112
 
113
113
  def redis
@@ -222,7 +222,7 @@ module Familia
222
222
  def to_redis v
223
223
  return v unless @opts[:class]
224
224
  ret = case @opts[:class]
225
- when ::String, ::Fixnum, ::Float, Gibbler::Digest
225
+ when ::Symbol, ::String, ::Fixnum, ::Float, Gibbler::Digest
226
226
  v
227
227
  else
228
228
  if ::String === v
@@ -250,37 +250,54 @@ module Familia
250
250
  ret
251
251
  end
252
252
 
253
- def from_redis v
254
- return @opts[:default] if v.nil?
255
- return v unless @opts[:class]
253
+ def multi_from_redis *values
254
+ Familia.ld "multi_from_redis: (#{@opts}) #{values}"
255
+ return [] if values.empty?
256
+ return values.flatten unless @opts[:class]
256
257
  ret = case @opts[:class]
257
- when String
258
+ when ::String
258
259
  v.to_s
259
- when Fixnum, Float
260
+ when ::Symbol
261
+ v.to_s.to_sym
262
+ when ::Fixnum, ::Float
260
263
  @opts[:class].induced_from v
261
264
  else
262
- begin
263
- if @opts[:reference] == true
264
- @opts[:class].from_redis v
265
- else
266
- if @opts[:class].respond_to? load_method
267
- @opts[:class].send load_method, v
268
- else
269
- raise Familia::Problem, "No such method: #{@opts[:class]}##{load_method}"
265
+ objs = values
266
+
267
+ if @opts[:reference] == true
268
+ objs = @opts[:class].rawmultiget *values
269
+ end
270
+ objs.compact!
271
+ if @opts[:class].respond_to? load_method
272
+ objs.collect! { |obj|
273
+ begin
274
+ v = @opts[:class].send load_method, obj
275
+ if v.nil?
276
+ Familia.ld "[#{self.class}\#multi_from_redis] nil returned for #{@opts[:class]}\##{name}"
277
+ end
278
+ v
279
+ rescue => ex
280
+ Familia.info v
281
+ Familia.info "Parse error for #{rediskey} (#{load_method}): #{ex.message}"
282
+ Familia.info ex.backtrace
283
+ nil
270
284
  end
271
- end
272
- rescue => ex
273
- Familia.info v
274
- Familia.info "Parse error for #{rediskey} (#{load_method}): #{ex.message}"
275
- Familia.info ex.backtrace
276
- nil
285
+ }
286
+ else
287
+ raise Familia::Problem, "No such method: #{@opts[:class]}##{load_method}"
277
288
  end
278
- end
279
- if ret.nil?
280
- Familia.ld "[#{self.class}\#from_redis] nil returned for #{@opts[:class]}\##{name}"
289
+ objs.compact # don't use compact! b/c the return value appears in ret
281
290
  end
282
291
  ret
292
+ end
293
+
294
+ def from_redis v
295
+ return @opts[:default] if v.nil?
296
+ return v unless @opts[:class]
297
+ ret = multi_from_redis v
298
+ ret.first unless ret.nil? # return the object or nil
283
299
  end
300
+
284
301
  end
285
302
 
286
303
 
@@ -347,14 +364,10 @@ module Familia
347
364
  alias_method :del, :delete
348
365
 
349
366
  def range sidx=0, eidx=-1
350
- # TODO: Use mget here and everywhere like it.
351
- #if @opts[:reference] == true
352
- # redis.lrange(rediskey, sidx, eidx)
353
- #else
354
- redis.lrange(rediskey, sidx, eidx).collect { |v| from_redis(v) }.compact
355
- #end
367
+ el = rangeraw sidx, eidx
368
+ multi_from_redis *el
356
369
  end
357
-
370
+
358
371
  def rangeraw sidx=0, eidx=-1
359
372
  redis.lrange(rediskey, sidx, eidx)
360
373
  end
@@ -468,7 +481,8 @@ module Familia
468
481
 
469
482
  def members
470
483
  echo :members, caller[0] if Familia.debug
471
- redis.smembers(rediskey).collect { |v| from_redis(v) }.compact
484
+ el = membersraw
485
+ multi_from_redis *el
472
486
  end
473
487
  alias_method :all, :members
474
488
  alias_method :to_a, :members
@@ -534,7 +548,11 @@ module Familia
534
548
  end
535
549
 
536
550
  def random
537
- from_redis redis.srandmember(rediskey)
551
+ from_redis randomraw
552
+ end
553
+
554
+ def randomraw
555
+ redis.srandmember(rediskey)
538
556
  end
539
557
 
540
558
  ## Make the value stored at KEY identical to the given list
@@ -610,7 +628,8 @@ module Familia
610
628
 
611
629
  def members count=-1, opts={}
612
630
  count -= 1 if count > 0
613
- range 0, count, opts
631
+ el = membersraw count, opts
632
+ multi_from_redis *el
614
633
  end
615
634
  alias_method :to_a, :members
616
635
  alias_method :all, :members
@@ -622,7 +641,8 @@ module Familia
622
641
 
623
642
  def revmembers count=-1, opts={}
624
643
  count -= 1 if count > 0
625
- revrange 0, count, opts
644
+ el = revmembersraw count, opts
645
+ multi_from_redis *el
626
646
  end
627
647
 
628
648
  def revmembersraw count=-1, opts={}
@@ -664,19 +684,21 @@ module Familia
664
684
 
665
685
  def range sidx, eidx, opts={}
666
686
  echo :range, caller[0] if Familia.debug
667
- rangeraw(sidx, eidx, opts).collect { |v| from_redis(v) }.compact
668
- end
669
-
670
- def revrange sidx, eidx, opts={}
671
- echo :revrange, caller[0] if Familia.debug
672
- revrangeraw(sidx, eidx, opts).collect { |v| from_redis(v) }.compact
687
+ el = rangeraw(sidx, eidx, opts)
688
+ multi_from_redis *el
673
689
  end
674
-
690
+
675
691
  def rangeraw sidx, eidx, opts={}
676
692
  opts[:with_scores] = true if opts[:withscores]
677
693
  redis.zrange(rediskey, sidx, eidx, opts)
678
694
  end
679
-
695
+
696
+ def revrange sidx, eidx, opts={}
697
+ echo :revrange, caller[0] if Familia.debug
698
+ el = revrangeraw(sidx, eidx, opts)
699
+ multi_from_redis *el
700
+ end
701
+
680
702
  def revrangeraw sidx, eidx, opts={}
681
703
  opts[:with_scores] = true if opts[:withscores]
682
704
  redis.zrevrange(rediskey, sidx, eidx, opts)
@@ -685,7 +707,8 @@ module Familia
685
707
  # e.g. obj.metrics.rangebyscore (now-12.hours), now, :limit => [0, 10]
686
708
  def rangebyscore sscore, escore, opts={}
687
709
  echo :rangebyscore, caller[0] if Familia.debug
688
- rangebyscoreraw(sscore, escore, opts).collect { |v| from_redis( v) }.compact
710
+ el = rangebyscoreraw(sscore, escore, opts)
711
+ multi_from_redis *el
689
712
  end
690
713
 
691
714
  def rangebyscoreraw sscore, escore, opts={}
@@ -777,9 +800,8 @@ module Familia
777
800
  end
778
801
 
779
802
  def values
780
- redis.hvals(rediskey).collect do |v|
781
- from_redis v
782
- end
803
+ el = redis.hvals(rediskey)
804
+ multi_from_redis *el
783
805
  end
784
806
 
785
807
  def all
@@ -824,9 +846,8 @@ module Familia
824
846
  alias_method :merge!, :update
825
847
 
826
848
  def values_at *names
827
- redis.hmget(rediskey, *names.flatten.compact).collect do |v|
828
- from_redis v
829
- end
849
+ el = redis.hmget(rediskey, *names.flatten.compact)
850
+ multi_from_redis *el
830
851
  end
831
852
 
832
853
  Familia::RedisObject.register self, :hash
@@ -847,7 +868,7 @@ module Familia
847
868
  end
848
869
 
849
870
  def value
850
- echo :value, caller[0] if Familia.debug
871
+ echo :value, caller[0..5] if Familia.debug
851
872
  redis.setnx rediskey, @opts[:default] if @opts[:default]
852
873
  from_redis redis.get(rediskey)
853
874
  end
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: familia
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 6
9
- - 10
10
- version: 0.6.10
4
+ prerelease:
5
+ version: 0.7.0
11
6
  platform: ruby
12
7
  authors:
13
8
  - Delano Mandelbaum
@@ -15,7 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-02-08 00:00:00 -05:00
13
+ date: 2011-03-04 00:00:00 -05:00
19
14
  default_executable:
20
15
  dependencies:
21
16
  - !ruby/object:Gem::Dependency
@@ -26,11 +21,6 @@ dependencies:
26
21
  requirements:
27
22
  - - ">="
28
23
  - !ruby/object:Gem::Version
29
- hash: 11
30
- segments:
31
- - 2
32
- - 1
33
- - 0
34
24
  version: 2.1.0
35
25
  type: :runtime
36
26
  version_requirements: *id001
@@ -42,11 +32,6 @@ dependencies:
42
32
  requirements:
43
33
  - - ">="
44
34
  - !ruby/object:Gem::Version
45
- hash: 11
46
- segments:
47
- - 0
48
- - 4
49
- - 2
50
35
  version: 0.4.2
51
36
  type: :runtime
52
37
  version_requirements: *id002
@@ -58,11 +43,6 @@ dependencies:
58
43
  requirements:
59
44
  - - ">="
60
45
  - !ruby/object:Gem::Version
61
- hash: 51
62
- segments:
63
- - 0
64
- - 8
65
- - 6
66
46
  version: 0.8.6
67
47
  type: :runtime
68
48
  version_requirements: *id003
@@ -74,11 +54,6 @@ dependencies:
74
54
  requirements:
75
55
  - - ">="
76
56
  - !ruby/object:Gem::Version
77
- hash: 51
78
- segments:
79
- - 0
80
- - 8
81
- - 6
82
57
  version: 0.8.6
83
58
  type: :runtime
84
59
  version_requirements: *id004
@@ -128,23 +103,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
128
103
  requirements:
129
104
  - - ">="
130
105
  - !ruby/object:Gem::Version
131
- hash: 3
132
- segments:
133
- - 0
134
106
  version: "0"
135
107
  required_rubygems_version: !ruby/object:Gem::Requirement
136
108
  none: false
137
109
  requirements:
138
110
  - - ">="
139
111
  - !ruby/object:Gem::Version
140
- hash: 3
141
- segments:
142
- - 0
143
112
  version: "0"
144
113
  requirements: []
145
114
 
146
115
  rubyforge_project: familia
147
- rubygems_version: 1.3.7
116
+ rubygems_version: 1.5.2
148
117
  signing_key:
149
118
  specification_version: 3
150
119
  summary: Organize and store ruby objects in Redis