summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-04-13 17:18:07 +0000
committerGerrit Code Review <review@openstack.org>2015-04-13 17:18:07 +0000
commite6f12dee2441b7941e5cf7ae218029a246502b0a (patch)
treeab20c099e416027343acbd7a5ee5753d5536b634
parentb3e8c1bd05bf2d8738294b7bc6016d9905e8d5ca (diff)
parent671c60d3a5c21169978805ca4ed616941a3aeabf (diff)
downloadoslo-messaging-e6f12dee2441b7941e5cf7ae218029a246502b0a.tar.gz
Merge "Fix the bug redis do not delete the expired keys" into stable/kilo
-rw-r--r--oslo_messaging/_drivers/matchmaker_redis.py7
-rw-r--r--oslo_messaging/tests/drivers/test_matchmaker_redis.py8
2 files changed, 14 insertions, 1 deletions
diff --git a/oslo_messaging/_drivers/matchmaker_redis.py b/oslo_messaging/_drivers/matchmaker_redis.py
index 4f6e6f0..290b603 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 097029d..7760404 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)