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); }