Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fix get_some validation/overwrite bug. thanks kgale and mhat

  • Loading branch information...
commit 4ce70ce471fffe173b9e80d0b36b53ce959c6a59 1 parent 4238b97
Justin Balthrop authored September 24, 2010
3  lib/memcache.rb
@@ -260,11 +260,10 @@ def get_some(keys, opts = {})
260 260
     end
261 261
 
262 262
     keys_to_fetch = keys - records.keys
263  
-    method = opts[:overwrite] ? :set : :add
264 263
     if keys_to_fetch.any?
265 264
       yield(keys_to_fetch).each do |key, value|
266 265
         begin
267  
-          self.send(method, key, value, opts) unless opts[:disable] or opts[:disable_write]
  266
+          set(key, value, {}) unless opts[:disable] or opts[:disable_write]
268 267
         rescue Memcache::Error => e
269 268
           raise if opts[:strict_write]
270 269
           $stderr.puts "Memcache error in get_some: #{e.class} #{e.to_s} on key '#{key}' while storing value: #{value}"
25  test/memcache_test.rb
@@ -157,6 +157,31 @@ def test_get_some
157 157
     end
158 158
   end
159 159
 
  160
+  def test_get_some_with_validation
  161
+    100.times do |i|
  162
+      m.set(i.to_s, i.odd? ? -i : i)
  163
+    end
  164
+    keys = (0...100).collect {|key| key.to_s}
  165
+
  166
+    results = m.get_some(keys, :validation => lambda {|k,v| k.to_i == v}) do |missing_keys|
  167
+      assert_equal 50, missing_keys.size
  168
+      r = {}
  169
+      missing_keys.each do |key|
  170
+        r[key] = key.to_i
  171
+      end
  172
+      r
  173
+    end
  174
+    assert_equal 100, results.size
  175
+
  176
+    results.each do |key, value|
  177
+      assert_equal key.to_i, value
  178
+    end
  179
+
  180
+    results = m.get_some(keys, :validation => lambda {|k,v| k.to_i == v}) do |missing_keys|
  181
+      flunk "no values should be invalid"
  182
+    end
  183
+  end
  184
+
160 185
   def test_get_with_reset_expiry
161 186
     m.add('foo', 'quick brown fox', :expiry => 1)
162 187
     assert_equal 'quick brown fox', m.get('foo', :expiry => 2)

0 notes on commit 4ce70ce

Please sign in to comment.
Something went wrong with that request. Please try again.