redis-objects 0.2.4 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,37 @@
1
+ = Changelog for Redis::Objects
2
+
3
+ == 0.3.0 [Final] (14 April 2010)
4
+
5
+ * Due to Ruby 1.9 bugs and performance considerations, marshaling of
6
+ data types is now OFF by default. You must say :marshal => true for
7
+ any objects that you want serialization enabled on. [Nate Wiger]
8
+
9
+ * Sorted Set class changed slightly due to feedback. You can now get
10
+ an individual element back via @set['item'] since it acts like a Hash.
11
+
12
+ == 0.2.4 [Final] (9 April 2010)*
13
+
14
+ * Added sorted set support via Redis::SortedSet [Nate Wiger]
15
+
16
+ == 0.2.3 [Final] (18 February 2010)*
17
+
18
+ * Added lock expiration to Redis::Lock [Ben VandenBos]
19
+
20
+ * Fixed some bugs [Ben VandenBos]
21
+
22
+ * Added lock tests and test helpers [Ben VandenBos]
23
+
24
+ == 0.2.2 [Final] (14 December 2009)*
25
+
26
+ * Added @set.diff(@set2) with "^" and "-" synonyms (oversight). [Nate Wiger]
27
+
28
+ * Implemented Redis core commands in all data types, such as rename. [Nate Wiger]
29
+
30
+ * Renamed Redis::Serialize to Redis::Helpers::Serialize to keep Redis:: cleaner. [Nate Wiger]
31
+
32
+ * More spec coverage. [Nate Wiger]
33
+
34
+ == 0.2.1 [Final] (27 November 2009)*
35
+
36
+ * First worthwhile public release, with good spec coverage and functionality. [Nate Wiger]
37
+
data/README.rdoc CHANGED
@@ -12,7 +12,7 @@ to Ruby objects, via a thin layer over Ezra's +redis+ gem. It offers several ad
12
12
  over the lower-level redis-rb API:
13
13
 
14
14
  1. Easy to integrate directly with existing ORMs - ActiveRecord, DataMapper, etc. Add counters to your model!
15
- 2. Complex data structures are automatically Marshaled
15
+ 2. Complex data structures are automatically Marshaled (if you set :marshal => true)
16
16
  3. Integers are returned as integers, rather than '17'
17
17
  4. Higher-level types are provided, such as Locks, that wrap multiple calls
18
18
 
@@ -171,10 +171,10 @@ Simple values are easy as well:
171
171
  @value.value = 'a'
172
172
  @value.delete
173
173
 
174
- Of course complex data is no problem:
174
+ Complex data is no problem with :marshal => true:
175
175
 
176
176
  @account = Account.create!(params[:account])
177
- @newest = Redis::Value.new('newest_account')
177
+ @newest = Redis::Value.new('newest_account', :marshal => true)
178
178
  @newest.value = @account.attributes
179
179
  puts @newest.value['username']
180
180
 
@@ -198,16 +198,15 @@ Lists work just like Ruby arrays:
198
198
  @list.clear
199
199
  # etc
200
200
 
201
- Complex data types are no problem:
201
+ Complex data types are no problem with :marshal => true:
202
202
 
203
+ @list = Redis::List.new('list_name', :marshal => true)
203
204
  @list << {:name => "Nate", :city => "San Diego"}
204
205
  @list << {:name => "Peter", :city => "Oceanside"}
205
206
  @list.each do |el|
206
207
  puts "#{el[:name]} lives in #{el[:city]}"
207
208
  end
208
209
 
209
- This gem will automatically marshal complex data, similar to how session stores work.
210
-
211
210
  === Sets
212
211
 
213
212
  Sets work like the Ruby {Set}[http://ruby-doc.org/core/classes/Set.html] class:
@@ -248,8 +247,10 @@ Or store them in Redis:
248
247
  @set1.diffstore('diffname', @set2, @set3)
249
248
  members = @set1.redis.get('diffname')
250
249
 
251
- And use complex data types too:
250
+ And use complex data types too, with :marshal => true:
252
251
 
252
+ @set1 = Redis::Set.new('set1', :marshal => true)
253
+ @set2 = Redis::Set.new('set2', :marshal => true)
253
254
  @set1 << {:name => "Nate", :city => "San Diego"}
254
255
  @set1 << {:name => "Peter", :city => "Oceanside"}
255
256
  @set2 << {:name => "Nate", :city => "San Diego"}
@@ -269,15 +270,20 @@ a Hash and an Array. You assign like a Hash, but retrieve like an Array:
269
270
  @sorted_set['Nate'] = 15
270
271
  @sorted_set['Peter'] = 75
271
272
  @sorted_set['Jeff'] = 24
272
-
273
- # atomic increment
274
- @sorted_set.increment('Nate')
275
- @sorted_set.incr('Peter') # shorthand
276
- @sorted_set.incr('Jeff', 4)
277
273
 
278
- @sorted_set[0,2] # => ["Nate", "Jeff", "Peter"]
274
+ # Array access to get sorted order
275
+ @sorted_set[0..2] # => ["Nate", "Jeff", "Peter"]
276
+ @sorted_set[0,2] # => ["Nate", "Jeff"]
277
+
278
+ @sorted_set['Peter'] # => 75
279
+ @sorted_set['Jeff'] # => 24
280
+ @sorted_set.score('Jeff') # same thing (24)
281
+
282
+ @sorted_set.rank('Peter') # => 2
283
+ @sorted_set.rank('Jeff') # => 1
284
+
279
285
  @sorted_set.first # => "Nate"
280
- @sorted_set.last # => "Nate"
286
+ @sorted_set.last # => "Peter"
281
287
  @sorted_set.revrange(0,2) # => ["Peter", "Jeff", "Nate"]
282
288
 
283
289
  @sorted_set['Newbie'] = 1
@@ -286,7 +292,12 @@ a Hash and an Array. You assign like a Hash, but retrieve like an Array:
286
292
  @sorted_set.rangebyscore(10, 100, :limit => 2) # => ["Nate", "Jeff"]
287
293
  @sorted_set.members(:withscores => true) # => [["Newbie", 1], ["Nate", 16], ["Jeff", 28], ["Peter", 76]]
288
294
 
289
- The other Redis Sorted Set commands are supported as well; see {SortedSets API}[http://code.google.com/p/redis/wiki/SortedSets].
295
+ # atomic increment
296
+ @sorted_set.increment('Nate')
297
+ @sorted_set.incr('Peter') # shorthand
298
+ @sorted_set.incr('Jeff', 4)
299
+
300
+ The other Redis Sorted Set commands are supported as well; see {Sorted Sets API}[http://code.google.com/p/redis/wiki/SortedSets].
290
301
 
291
302
  == Atomic Counters and Locks
292
303
 
@@ -4,6 +4,7 @@ class Redis
4
4
  include Marshal
5
5
 
6
6
  def to_redis(value)
7
+ return value unless options[:marshal]
7
8
  case value
8
9
  when String, Fixnum, Bignum, Float
9
10
  value
@@ -13,6 +14,7 @@ class Redis
13
14
  end
14
15
 
15
16
  def from_redis(value)
17
+ return value unless options[:marshal]
16
18
  case value
17
19
  when Array
18
20
  value.collect{|v| from_redis(v)}
data/lib/redis/list.rb CHANGED
@@ -62,7 +62,7 @@ class Redis
62
62
  at(index)
63
63
  end
64
64
  end
65
-
65
+
66
66
  # Delete the element(s) from the list that match name. If count is specified,
67
67
  # only the first-N (if positive) or last-N (if negative) will be removed.
68
68
  # Use .del to completely delete the entire key.
@@ -42,7 +42,7 @@ class Redis
42
42
  elsif length
43
43
  range(index, length)
44
44
  else
45
- at(index)
45
+ score(index)
46
46
  end
47
47
  end
48
48
 
@@ -27,15 +27,24 @@ describe Redis::Value do
27
27
  end
28
28
 
29
29
  it "should handle complex marshaled values" do
30
+ @value.options[:marshal] = true
30
31
  @value.should == nil
31
32
  @value.value = {:json => 'data'}
32
33
  @value.should == {:json => 'data'}
33
- @value.get.should == {:json => 'data'}
34
+
35
+ # no marshaling
36
+ @value.options[:marshal] = false
37
+ v = {:json => 'data'}
38
+ @value.value = v
39
+ @value.should == v.to_s
40
+
41
+ @value.options[:marshal] = true
34
42
  @value.value = [[1,2], {:t3 => 4}]
35
43
  @value.should == [[1,2], {:t3 => 4}]
36
44
  @value.get.should == [[1,2], {:t3 => 4}]
37
45
  @value.del.should be_true
38
46
  @value.should be_nil
47
+ @value.options[:marshal] = false
39
48
  end
40
49
 
41
50
  it "should support renaming values" do
@@ -106,6 +115,7 @@ describe Redis::List do
106
115
  @list << 'j'
107
116
  @list.should == ['a','c','f','j']
108
117
  @list[0..2].should == ['a','c','f']
118
+ @list[0, 2].should == ['a','c','f'] # consistent with Redis, not Ruby
109
119
  @list[1, 3].should == ['c','f','j']
110
120
  @list.length.should == 4
111
121
  @list.size.should == 4
@@ -138,13 +148,17 @@ describe Redis::List do
138
148
  end
139
149
 
140
150
  it "should handle lists of complex data types" do
141
- @list << {:json => 'data'}
142
- @list << {:json2 => 'data2'}
143
- @list.first.should == {:json => 'data'}
144
- @list.last.should == {:json2 => 'data2'}
151
+ @list.options[:marshal] = true
152
+ v1 = {:json => 'data'}
153
+ v2 = {:json2 => 'data2'}
154
+ @list << v1
155
+ @list << v2
156
+ @list.first.should == v1
157
+ @list.last.should == v2
145
158
  @list << [1,2,3,[4,5]]
146
159
  @list.last.should == [1,2,3,[4,5]]
147
160
  @list.shift.should == {:json => 'data'}
161
+ @list.options[:marshal] = false
148
162
  end
149
163
 
150
164
  it "should support renaming lists" do
@@ -442,15 +456,20 @@ describe Redis::SortedSet do
442
456
  @set['a'] = 21
443
457
  @set.add('a', 5)
444
458
  @set.score('a').should == 5
459
+ @set['a'].should == 5
445
460
  @set['a'] = 3
446
461
  @set['b'] = 5
462
+ @set['b'].should == 5
447
463
  @set['c'] = 4
448
464
 
449
465
  @set[0,-1].should == ['a','c','b']
466
+ @set[0..2].should == ['a','c','b']
467
+ @set[0,2].should == ['a','c','b'] # consistent with Redis, not Ruby
468
+ @set.range(0,1,:withscores => true).should == [['a',3],['c',4]]
450
469
  @set.range(0,-1).should == ['a','c','b']
451
470
  @set.revrange(0,-1).should == ['b','c','a']
452
471
  @set[0..1].should == ['a','c']
453
- @set[1].should == 'c'
472
+ @set[1].should == 0 # missing
454
473
  @set.at(1).should == 'c'
455
474
  @set.first.should == 'a'
456
475
  @set.last.should == 'b'
@@ -10,9 +10,9 @@ class Roster
10
10
  counter :pitchers, :limit => :max_pitchers
11
11
  counter :basic
12
12
  lock :resort, :timeout => 2
13
- value :starting_pitcher
14
- list :player_stats
15
- set :outfielders
13
+ value :starting_pitcher, :marshal => true
14
+ list :player_stats, :marshal => true
15
+ set :outfielders, :marshal => true
16
16
 
17
17
  # global class counters
18
18
  counter :total_players_online, :global => true
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
8
- - 4
9
- version: 0.2.4
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Nate Wiger
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-09 00:00:00 -07:00
17
+ date: 2010-04-14 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -39,7 +39,7 @@ extensions: []
39
39
 
40
40
  extra_rdoc_files:
41
41
  - ATOMICITY.rdoc
42
- - ChangeLog
42
+ - CHANGELOG.rdoc
43
43
  - README.rdoc
44
44
  files:
45
45
  - lib/redis/counter.rb
@@ -61,7 +61,7 @@ files:
61
61
  - spec/redis_objects_model_spec.rb
62
62
  - spec/spec_helper.rb
63
63
  - ATOMICITY.rdoc
64
- - ChangeLog
64
+ - CHANGELOG.rdoc
65
65
  - README.rdoc
66
66
  has_rdoc: true
67
67
  homepage: http://github.com/nateware/redis-objects
data/ChangeLog DELETED
@@ -1,23 +0,0 @@
1
-
2
- *0.2.3 [Final] (18 February 2010)*
3
-
4
- * Added lock expiration to Redis::Lock [Ben VandenBos]
5
-
6
- * Fixed some bugs [Ben VandenBos]
7
-
8
- * Added lock tests and test helpers [Ben VandenBos]
9
-
10
- *0.2.2 [Final] (14 December 2009)*
11
-
12
- * Added @set.diff(@set2) with "^" and "-" synonyms (oversight). [Nate Wiger]
13
-
14
- * Implemented Redis core commands in all data types, such as rename. [Nate Wiger]
15
-
16
- * Renamed Redis::Serialize to Redis::Helpers::Serialize to keep Redis:: cleaner. [Nate Wiger]
17
-
18
- * More spec coverage. [Nate Wiger]
19
-
20
- *0.2.1 [Final] (27 November 2009)*
21
-
22
- * First worthwhile public release, with good spec coverage and functionality. [Nate Wiger]
23
-