Merge "Fix the bug redis do not delete the expired keys"

This commit is contained in:
Jenkins 2015-03-16 01:48:14 +00:00 committed by Gerrit Code Review
commit ec68634d91
2 changed files with 14 additions and 1 deletions

View File

@ -108,7 +108,12 @@ class MatchMakerRedis(mm_common.HeartbeatMatchMakerBase):
self.register(key, host)
def is_alive(self, topic, host):
if self.redis.ttl(host) == -1:
# After redis 2.8, if the specialized key doesn't exist,
# TTL fuction would return -2. If key exists,
# but doesn't have expiration associated,
# TTL func would return -1. For more information,
# please visit http://redis.io/commands/ttl
if self.redis.ttl(host) == -2:
self.expire(topic, host)
return False
return True

View File

@ -87,3 +87,11 @@ class RedisMatchMakerTest(test_utils.BaseTestCase):
self.assertEqual(
sorted(self.matcher.redis.smembers('ack_alive')),
['ack_alive.controller1'])
def test_is_alive(self):
self.assertEqual(
self.matcher.is_alive('conductor', 'conductor.controller1'),
True)
self.assertEqual(
self.matcher.is_alive('conductor', 'conductor.controller2'),
False)