Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add persist support, fix bug in ttl #53

Merged
merged 2 commits into from

2 participants

@yaauie
  • added support for persist on all redis-objects
  • added test coverage for expire, ttl, and persist
  • fixed bug in ttl, which sends missing method seconds to the return of redis.ttl(key), an Integer.
@nateware nateware merged commit 4087b1e into nateware:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
6 lib/redis/helpers/core_commands.rb
@@ -38,8 +38,12 @@ def expireat(unixtime)
redis.expire key, unixtime
end
+ def persist
+ redis.persist key
+ end
+
def ttl
- redis.ttl(@key).seconds
+ redis.ttl(@key)
end
def move(dbindex)
View
20 spec/redis_objects_model_spec.rb
@@ -142,6 +142,26 @@ class CustomMethodRoster < MethodRoster
@roster.contact_information.size.should == 2
end
+ it 'should be able to expire keys and then persist them' do
+ # on a hash_key
+ @roster.contact_information['Jenny_Phone'] = '8675309'
+ @roster.contact_information.expire 30
+ @roster.contact_information.ttl.should > -1
+ @roster.contact_information.ttl.should <= 30
+ @roster.contact_information.persist
+ @roster.contact_information.ttl.should == -1
+ @roster.contact_information['Jenny_Phone'].should == '8675309'
+
+ # on a value
+ @roster.my_rank = 42
+ @roster.my_rank.expire 30
+ @roster.my_rank.ttl.should > -1
+ @roster.my_rank.ttl.should <= 30
+ @roster.my_rank.persist
+ @roster.my_rank.ttl.should == -1
+ @roster.my_rank.to_i.should == 42
+ end
+
it "should be marshalling hash keys" do
@roster.contact_information['updated_at'] = Time.now
@roster.contact_information['updated_at'].class.should == Time
Something went wrong with that request. Please try again.