Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fix tests, and shim for old memcached support

  • Loading branch information...
commit b8ed0c306d4f9ed6d04ac7ac17a8b46cea699dcf 1 parent b70f450
Matt Freels authored

Showing 2 changed files with 18 additions and 7 deletions. Show diff stats Hide diff stats

  1. +14 3 lib/kestrel/client.rb
  2. +4 4 spec/kestrel/client_spec.rb
17 lib/kestrel/client.rb
@@ -62,9 +62,20 @@ def get_from_random(key, raw=false)
62 62 rescue Memcached::NotFound
63 63 end
64 64
65   - def get_from_last(key, raw=false)
66   - super key, !raw
67   - rescue Memcached::NotFound
  65 + # use get_from_last if available, otherwise redefine to point to
  66 + # plain old get
  67 + if method_defined? :get_from_last
  68 + def get_from_last(key, raw=false)
  69 + super key, !raw
  70 + rescue Memcached::NotFound
  71 + end
  72 + else
  73 +
  74 + $stderr.puts "You have an older version of memcached.gem. Please upgrade to 0.19.6 or later for sticky get behavior."
  75 + def get_from_last(key, raw=false)
  76 + _super_get_from_random key, !raw
  77 + rescue Memcached::NotFound
  78 + end
68 79 end
69 80
70 81 def delete(key, expiry=0)
8 spec/kestrel/client_spec.rb
@@ -18,15 +18,15 @@
18 18 end
19 19
20 20 it "gets from the same server :gets_per_server times" do
21   - mock(@kestrel).get_from_last("a_queue/t=250", false).times(100) { 'item' }
22   - mock(@kestrel).get_from_random("a_queue/t=250", false).times(2) { 'item' }
  21 + mock(@kestrel).get_from_last("a_queue/t=10", false).times(100) { 'item' }
  22 + mock(@kestrel).get_from_random("a_queue/t=10", false).times(2) { 'item' }
23 23
24 24 102.times { @kestrel.get("a_queue") }
25 25 end
26 26
27 27 it "gets from a different server when the last result was nil" do
28   - mock(@kestrel).get_from_last("a_queue/t=250", false).never { nil }
29   - mock(@kestrel).get_from_random("a_queue/t=250", false).times(3) { nil }
  28 + mock(@kestrel).get_from_last("a_queue/t=10", false).never { nil }
  29 + mock(@kestrel).get_from_random("a_queue/t=10", false).times(3) { nil }
30 30
31 31 3.times { @kestrel.get("a_queue") }
32 32 end

0 comments on commit b8ed0c3

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