Skip to content

Implement persist command #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions mockredis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,14 @@ def expireat(self, key, when):
return True
return False

def persist(self, key):
"""Emulate persist"""
try:
del self.timeouts[key]
return True
except KeyError:
return False

def ttl(self, key):
"""
Emulate ttl
Expand Down
27 changes: 27 additions & 0 deletions mockredis/tests/test_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,33 @@ def test_expireat_calculates_time(self):
# should be less than the timeout originally set
ok_(result <= 30, "Expected {} to be less than 30".format(result))

def test_persist(self):
"""
Test whether persist removes ttl.
"""
self.redis.set('key', 'key')
self.redis.expire('key', 30)

result = self.redis.persist('key')
eq_(result, True)
eq_(self.redis.ttl('key'), None)

def test_persist_no_timeout(self):
"""
Test whether persist returns False when no timeout is set.
"""
self.redis.set('key', 'key')

result = self.redis.persist('key')
eq_(result, False)

def test_persist_no_key(self):
"""
Test whether persist returns False when key does not exist.
"""
result = self.redis.persist('key')
eq_(result, False)

def test_keys(self):
eq_([], self.redis.keys("*"))

Expand Down