Skip to content

Commit

Permalink
get returns Memcached::NotFound exception after set expire
Browse files Browse the repository at this point in the history
  • Loading branch information
flyerhzm committed Jul 20, 2012
1 parent d8d28a8 commit cf047e1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 4 additions & 0 deletions lib/memcached.rb
@@ -1,5 +1,6 @@
require 'java'
require 'memcached/version'
require 'memcached/exceptions'
require 'target/spymemcached-ext-0.0.1.jar'

class Memcached
Expand Down Expand Up @@ -41,6 +42,9 @@ def set(key, value, ttl=@default_ttl, marshal=true, flags=FLAGS)

def get(key, marshal=true)
ret = @client.get(key, @simple_transcoder)
if ret.nil?
raise Memcached::NotFound
end
flags, data = ret.flags, ret.data
value = String.from_java_bytes data
marshal ? Marshal.load(value) : value
Expand Down
1 change: 1 addition & 0 deletions lib/memcached/exceptions.rb
@@ -0,0 +1 @@
class Memcached::NotFound < Exception; end
15 changes: 11 additions & 4 deletions spec/memcached_spec.rb
Expand Up @@ -22,13 +22,20 @@
end

it "should set/get with plain text" do
@memcached.set("hello", "world")
@memcached.get("hello").should == "world"
@memcached.set "key", "value"
@memcached.get("key").should == "value"
end

it "should set/get with compressed text" do
@memcached.set("hello", "x\234c?P?*?/?I\001\000\b8\002a")
@memcached.get("hello").should == "x\234c?P?*?/?I\001\000\b8\002a"
@memcached.set "key", "x\234c?P?*?/?I\001\000\b8\002a"
@memcached.get("key").should == "x\234c?P?*?/?I\001\000\b8\002a"
end

it "should set expiry" do
@memcached.set "key", "value", 1
@memcached.get("key").should == "value"
sleep 1
lambda { @memcached.get("key") }.should raise_error(Memcached::NotFound)
end
end
end

0 comments on commit cf047e1

Please sign in to comment.