familia 0.6.9 → 0.6.10

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.txt CHANGED
@@ -1,5 +1,15 @@
1
1
  FAMILIA, CHANGES
2
2
 
3
+ #### 0.6.10 (2011-01-08) ###############################
4
+
5
+ * FIXED: RedisObject#db does not set @db
6
+ * CHANGE: RedisObject#to_redis returns the original String if the given value
7
+ is a String, even if :class is specified.
8
+ * CHANGE: Update expiration when adding to List, Set, SortedSet, and HashKey
9
+ * CHANGE: Only call Familia.ld when in debug mode.
10
+ * ADDED: RedisObject#rename, renamenx, persist
11
+
12
+
3
13
  #### 0.6.9 (2011-01-09) ###############################
4
14
 
5
15
  * ADDED: RedisObject#cache
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :MAJOR: 0
3
3
  :MINOR: 6
4
- :PATCH: 9
4
+ :PATCH: 10
data/familia.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{familia}
8
- s.version = "0.6.9"
8
+ s.version = "0.6.10"
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-10}
12
+ s.date = %q{2011-02-08}
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 = [
data/lib/familia.rb CHANGED
@@ -28,7 +28,7 @@ module Familia
28
28
  @classes = []
29
29
  @suffix = :object.freeze
30
30
  @index = :id.freeze
31
- @debug = false.freeze
31
+ @debug = false
32
32
  @dump_method = :to_json
33
33
  @load_method = :from_json
34
34
  class << self
@@ -89,7 +89,6 @@ module Familia
89
89
  conf[:logger] = Familia.logger
90
90
  end
91
91
  redis = Redis.new conf
92
- p redis.client.logger
93
92
  Familia.trace :CONNECT, redis, conf.inspect, caller[0..3] if Familia.debug
94
93
  @clients[uri.serverid] = redis
95
94
  end
@@ -226,7 +226,7 @@ module Familia
226
226
  def rawmultiget(*ids)
227
227
  ids.collect! { |objid| rediskey(objid) }
228
228
  return [] if ids.compact.empty?
229
- Familia.trace :MULTIGET, self.redis, "#{ids.size}: #{ids}", caller
229
+ Familia.trace :MULTIGET, self.redis, "#{ids.size}: #{ids}", caller if Familia.debug?
230
230
  ids = self.redis.mget *ids
231
231
  end
232
232
 
@@ -257,7 +257,7 @@ module Familia
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
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
268
+ Familia.trace :EXISTS, Familia.redis(self.uri), "#{rediskey(idx, suffix)} #{ret}", caller.first 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
273
+ Familia.trace :DELETED, Familia.redis(self.uri), "#{rediskey(idx, suffix)}: #{ret}", caller.first if Familia.debug?
274
274
  ret
275
275
  end
276
276
  def find suffix='*'
@@ -287,7 +287,7 @@ module Familia
287
287
  end
288
288
  def expand(short_idx, suffix=self.suffix)
289
289
  expand_key = Familia.rediskey(self.prefix, "#{short_idx}*", suffix)
290
- Familia.trace :EXPAND, Familia.redis(self.uri), expand_key, caller.first
290
+ Familia.trace :EXPAND, Familia.redis(self.uri), expand_key, caller.first if Familia.debug?
291
291
  list = Familia.redis(self.uri).keys expand_key
292
292
  case list.size
293
293
  when 0
@@ -360,7 +360,7 @@ module Familia
360
360
 
361
361
  def allkeys
362
362
  # TODO: Use redis_objects instead
363
- keynames = [rediskey]
363
+ keynames = []
364
364
  self.class.suffixes.each do |sfx|
365
365
  keynames << rediskey(sfx)
366
366
  end
@@ -381,7 +381,7 @@ module Familia
381
381
  self.class.rediskey self.index, suffix
382
382
  end
383
383
  def save
384
- #Familia.trace :SAVE, Familia.redis(self.class.uri), redisuri, caller.first
384
+ #Familia.trace :SAVE, Familia.redis(self.class.uri), redisuri, caller.first if Familia.debug?
385
385
  preprocess if respond_to?(:preprocess)
386
386
  self.update_time if self.respond_to?(:update_time)
387
387
  # TODO: Check here (run checkup)
@@ -396,7 +396,7 @@ module Familia
396
396
  def destroy!
397
397
  ret = self.object.delete
398
398
  if Familia.debug?
399
- Familia.trace :DELETED, Familia.redis(self.class.uri), "#{rediskey}: #{ret}", caller.first
399
+ Familia.trace :DELETED, Familia.redis(self.class.uri), "#{rediskey}: #{ret}", caller.first if Familia.debug?
400
400
  end
401
401
  self.class.instances.rem self if ret > 0
402
402
  ret
@@ -96,7 +96,7 @@ module Familia
96
96
  self.extend @opts[:extend] if Module === @opts[:extend]
97
97
  @db = @opts.delete(:db)
98
98
  @parent = @opts.delete(:parent)
99
- @ttl = @opts.delete(:ttl)
99
+ @ttl ||= @opts.delete(:ttl)
100
100
  @redis ||= @opts.delete(:redis)
101
101
  @cache = {}
102
102
  init if respond_to? :init
@@ -124,17 +124,16 @@ module Familia
124
124
  # After this is called once, this method will always return the
125
125
  # same value.
126
126
  def db
127
- return @db if @db
128
127
  # Note it's important that we select this value at the last
129
128
  # possible moment rather than in initialize b/c the value
130
129
  # could be modified after that but before this is called.
131
130
  if @opts[:class] && @opts[:class].ancestors.member?(Familia)
132
- @db = @opts[:class].db
131
+ @opts[:class].db
132
+ elsif parent?
133
+ parent.db
133
134
  else
134
- @db = parent? ? parent.db : self.class.db
135
+ self.class.db || @db || 0
135
136
  end
136
- @db ||= 0
137
- @db
138
137
  end
139
138
 
140
139
  def ttl
@@ -169,7 +168,13 @@ module Familia
169
168
  redis.move rediskey, db
170
169
  end
171
170
 
172
- # TODO: rename, renamenx
171
+ def rename newkey
172
+ redis.rename rediskey, newkey
173
+ end
174
+
175
+ def renamenx newkey
176
+ redis.renamenx rediskey, newkey
177
+ end
173
178
 
174
179
  def type
175
180
  redis.type rediskey
@@ -202,6 +207,10 @@ module Familia
202
207
  redis.expireat rediskey, unixtime
203
208
  end
204
209
 
210
+ def persist
211
+ redis.persist rediskey
212
+ end
213
+
205
214
  def dump_method
206
215
  @opts[:dump_method] || Familia.dump_method
207
216
  end
@@ -213,10 +222,13 @@ module Familia
213
222
  def to_redis v
214
223
  return v unless @opts[:class]
215
224
  ret = case @opts[:class]
216
- when String, Fixnum, Float, Gibbler::Digest
225
+ when ::String, ::Fixnum, ::Float, Gibbler::Digest
217
226
  v
218
227
  else
219
- if @opts[:reference] == true
228
+ if ::String === v
229
+ v
230
+
231
+ elsif @opts[:reference] == true
220
232
  unless v.respond_to? :index
221
233
  raise Familia::Problem, "#{v.class} does not have an index method"
222
234
  end
@@ -224,8 +236,10 @@ module Familia
224
236
  raise Familia::Problem, "#{v.class} is not Familia (#{name})"
225
237
  end
226
238
  v.index
239
+
227
240
  elsif v.respond_to? dump_method
228
241
  v.send dump_method
242
+
229
243
  else
230
244
  raise Familia::Problem, "No such method: #{v.class}.#{dump_method}"
231
245
  end
@@ -285,6 +299,7 @@ module Familia
285
299
  echo :push, caller[0] if Familia.debug
286
300
  values.flatten.compact.each { |v| redis.rpush rediskey, to_redis(v) }
287
301
  redis.ltrim rediskey, -@opts[:maxlength], -1 if @opts[:maxlength]
302
+ update_expiration
288
303
  self
289
304
  end
290
305
 
@@ -297,6 +312,7 @@ module Familia
297
312
  values.flatten.compact.each { |v| redis.lpush rediskey, to_redis(v) }
298
313
  # TODO: test maxlength
299
314
  redis.ltrim rediskey, 0, @opts[:maxlength] - 1 if @opts[:maxlength]
315
+ update_expiration
300
316
  self
301
317
  end
302
318
 
@@ -442,6 +458,7 @@ module Familia
442
458
 
443
459
  def add *values
444
460
  values.flatten.compact.each { |v| redis.sadd rediskey, to_redis(v) }
461
+ update_expiration
445
462
  self
446
463
  end
447
464
 
@@ -563,7 +580,9 @@ module Familia
563
580
 
564
581
  # NOTE: The argument order is the reverse of #[]=
565
582
  def add score, v
566
- redis.zadd rediskey, score, to_redis(v)
583
+ ret = redis.zadd rediskey, score, to_redis(v)
584
+ update_expiration
585
+ ret
567
586
  end
568
587
 
569
588
  def score v
@@ -731,7 +750,9 @@ module Familia
731
750
  end
732
751
 
733
752
  def []= n, v
734
- redis.hset rediskey, n, to_redis(v)
753
+ ret = redis.hset rediskey, n, to_redis(v)
754
+ update_expiration
755
+ ret
735
756
  end
736
757
  alias_method :put, :[]=
737
758
  alias_method :store, :[]=
@@ -796,7 +817,9 @@ module Familia
796
817
  def update h={}
797
818
  raise ArgumentError, "Argument to bulk_set must be a hash" unless Hash === h
798
819
  data = h.inject([]){ |ret,pair| ret << [pair[0], to_redis(pair[1])] }.flatten
799
- redis.hmset(rediskey, *data)
820
+ ret = redis.hmset(rediskey, *data)
821
+ update_expiration
822
+ ret
800
823
  end
801
824
  alias_method :merge!, :update
802
825
 
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: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 9
10
- version: 0.6.9
9
+ - 10
10
+ version: 0.6.10
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-10 00:00:00 -05:00
18
+ date: 2011-02-08 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency