Permalink
Browse files

fix get_some validation/overwrite bug. thanks kgale and mhat

  • Loading branch information...
1 parent 4238b97 commit 4ce70ce471fffe173b9e80d0b36b53ce959c6a59 @ninjudd committed Sep 24, 2010
Showing with 26 additions and 2 deletions.
  1. +1 −2 lib/memcache.rb
  2. +25 −0 test/memcache_test.rb
View
@@ -260,11 +260,10 @@ def get_some(keys, opts = {})
end
keys_to_fetch = keys - records.keys
- method = opts[:overwrite] ? :set : :add
if keys_to_fetch.any?
yield(keys_to_fetch).each do |key, value|
begin
- self.send(method, key, value, opts) unless opts[:disable] or opts[:disable_write]
+ set(key, value, {}) unless opts[:disable] or opts[:disable_write]
rescue Memcache::Error => e
raise if opts[:strict_write]
$stderr.puts "Memcache error in get_some: #{e.class} #{e.to_s} on key '#{key}' while storing value: #{value}"
View
@@ -157,6 +157,31 @@ def test_get_some
end
end
+ def test_get_some_with_validation
+ 100.times do |i|
+ m.set(i.to_s, i.odd? ? -i : i)
+ end
+ keys = (0...100).collect {|key| key.to_s}
+
+ results = m.get_some(keys, :validation => lambda {|k,v| k.to_i == v}) do |missing_keys|
+ assert_equal 50, missing_keys.size
+ r = {}
+ missing_keys.each do |key|
+ r[key] = key.to_i
+ end
+ r
+ end
+ assert_equal 100, results.size
+
+ results.each do |key, value|
+ assert_equal key.to_i, value
+ end
+
+ results = m.get_some(keys, :validation => lambda {|k,v| k.to_i == v}) do |missing_keys|
+ flunk "no values should be invalid"
+ end
+ end
+
def test_get_with_reset_expiry
m.add('foo', 'quick brown fox', :expiry => 1)
assert_equal 'quick brown fox', m.get('foo', :expiry => 2)

0 comments on commit 4ce70ce

Please sign in to comment.