From 74a5652ff09f9239ec9e5a37a4c4b0f18f8ddae7 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Fri, 17 Jun 2016 13:07:13 +0200 Subject: [PATCH] DATAREDIS-505 - Polishing. Extend date range in license header. Retrieve connection and config for possible reconfiguration only if keyspaceNotificationsConfigParameter has a value. Original pull request: #202. --- .../KeyspaceEventMessageListener.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/listener/KeyspaceEventMessageListener.java b/src/main/java/org/springframework/data/redis/listener/KeyspaceEventMessageListener.java index e50d2caec..4b9e66b57 100644 --- a/src/main/java/org/springframework/data/redis/listener/KeyspaceEventMessageListener.java +++ b/src/main/java/org/springframework/data/redis/listener/KeyspaceEventMessageListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -75,17 +75,22 @@ public abstract class KeyspaceEventMessageListener implements MessageListener, I */ public void init() { - RedisConnection connection = listenerContainer.getConnectionFactory().getConnection(); - List config = connection.getConfig("notify-keyspace-events"); - if (StringUtils.hasText(keyspaceNotificationsConfigParameter)) { - if (config.size() == 2) { - if (!StringUtils.hasText(config.get(1))) { + + RedisConnection connection = listenerContainer.getConnectionFactory().getConnection(); + + try { + + List config = connection.getConfig("notify-keyspace-events"); + + if (config.size() == 2 && !StringUtils.hasText(config.get(1))) { connection.setConfig("notify-keyspace-events", keyspaceNotificationsConfigParameter); } + + } finally { + connection.close(); } } - connection.close(); doRegister(listenerContainer); }