diff --git a/oslo_messaging/_drivers/matchmaker_redis.py b/oslo_messaging/_drivers/matchmaker_redis.py index 4f6e6f0df..290b60351 100644 --- a/oslo_messaging/_drivers/matchmaker_redis.py +++ b/oslo_messaging/_drivers/matchmaker_redis.py @@ -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 diff --git a/oslo_messaging/tests/drivers/test_matchmaker_redis.py b/oslo_messaging/tests/drivers/test_matchmaker_redis.py index 097029d42..77604040c 100644 --- a/oslo_messaging/tests/drivers/test_matchmaker_redis.py +++ b/oslo_messaging/tests/drivers/test_matchmaker_redis.py @@ -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)