Commit 79b3b79a authored by Rajko Albrecht's avatar Rajko Albrecht

better handling of ttl

parent 51f6bd33
......@@ -35,7 +35,7 @@ class Redis
value = get(key)
value = yield value
ires = multi do |multi|
multi.set(key,value,{:expire_in => ttl})
multi.set(key,value,ttl.nil? ? {} : {:expire_after => ttl})
end
return_value ires
end
......
......@@ -32,6 +32,21 @@ describe Redis::StoreWithCas do
assert_equal 'baz', @store.get('foo')
end
# TODO write a Mockup redis with support for watch
def test_cas_with_ttl
@store.set('ttlfoo','bar')
assert(@store.cas('ttlfoo',3600) do |value|
assert_equal 'bar',value
'ttlbar'
end)
assert_equal @store.get('ttlfoo'),'ttlbar'
assert @store.ttl('ttlfoo') > 0
assert(@store.cas('ttlfoo') do |value|
'bar'
end)
assert_equal -1,@store.ttl('ttlfoo')
end
def test_cas_multi_with_empty_set
refute @store.cas_multi { |_hash| flunk }
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment