private RedisConnection getConnection() { return connectionFactory.getConnection(); }
/** * Clear database before shut down. */ public @PreDestroy void flushTestDb() { factory.getConnection().flushDb(); }
private void executeLockFree(Consumer<RedisConnection> callback) { RedisConnection connection = connectionFactory.getConnection(); try { callback.accept(connection); } finally { connection.close(); } }
private <T> T execute(String name, Function<RedisConnection, T> callback) { RedisConnection connection = connectionFactory.getConnection(); try { checkAndPotentiallyWaitUntilUnlocked(name, connection); return callback.apply(connection); } finally { connection.close(); } }
@Override public void afterPropertiesSet() throws Exception { if (this.configure == ConfigureRedisAction.NO_OP) { return; } RedisConnection connection = this.connectionFactory.getConnection(); try { this.configure.configure(connection); } finally { try { connection.close(); } catch (Exception ex) { LogFactory.getLog(getClass()).error("Error closing RedisConnection", ex); } } }
@Override public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable { RedisCommand commandToExecute = RedisCommand.failsafeCommandLookup(method.getName()); if (isPotentiallyThreadBoundCommand(commandToExecute)) { if (log.isDebugEnabled()) { log.debug(String.format("Invoke '%s' on bound conneciton", method.getName())); } return invoke(method, obj, args); } if (log.isDebugEnabled()) { log.debug(String.format("Invoke '%s' on unbound conneciton", method.getName())); } RedisConnection connection = factory.getConnection(); try { return invoke(method, connection, args); } finally { // properly close the unbound connection after executing command if (!connection.isClosed()) { connection.close(); } } }
/** * Initialize the message listener by writing requried redis config for {@literal notify-keyspace-events} and * registering the listener within the container. */ public void init() { if (StringUtils.hasText(keyspaceNotificationsConfigParameter)) { RedisConnection connection = listenerContainer.getConnectionFactory().getConnection(); try { Properties config = connection.getConfig("notify-keyspace-events"); if (!StringUtils.hasText(config.getProperty("notify-keyspace-events"))) { connection.setConfig("notify-keyspace-events", keyspaceNotificationsConfigParameter); } } finally { connection.close(); } } doRegister(listenerContainer); }
@Override public Map<Long, CIMServerResVO> loadRouteRelated() { Map<Long, CIMServerResVO> routes = new HashMap<>(64); RedisConnection connection = redisTemplate.getConnectionFactory().getConnection(); ScanOptions options = ScanOptions.scanOptions() .match(ROUTE_PREFIX + "*") .build(); Cursor<byte[]> scan = connection.scan(options); while (scan.hasNext()) { byte[] next = scan.next(); String key = new String(next, StandardCharsets.UTF_8); LOGGER.info("key={}", key); parseServerInfo(routes, key); } try { scan.close(); } catch (IOException e) { LOGGER.error("IOException",e); } return routes; }
connection = connectionFactory.getConnection(); if (connection.isSubscribed()) { throw new IllegalStateException("Retrieved connection is already subscribed; aborting listening");
@Bean public RedisConnectionFactory connectionFactory() { RedisConnectionFactory factory = mock(RedisConnectionFactory.class); RedisConnection connection = mock(RedisConnection.class); given(factory.getConnection()).willReturn(connection); given(connection.getConfig(anyString())).willReturn(new Properties()); return factory; } }
@Bean public RedisConnectionFactory connectionFactory() { RedisConnectionFactory factory = mock(RedisConnectionFactory.class); RedisConnection connection = mock(RedisConnection.class); given(factory.getConnection()).willReturn(connection); given(connection.getConfig(anyString())).willReturn(new Properties()); return factory; } }
@Bean public RedisConnectionFactory redisConnectionFactory() { RedisConnectionFactory factory = mock(RedisConnectionFactory.class); RedisConnection connection = mock(RedisConnection.class); given(factory.getConnection()).willReturn(connection); given(connection.getConfig(anyString())).willReturn(new Properties()); return factory; } }
@Bean public RedisConnectionFactory connectionFactory() { RedisConnectionFactory factory = mock(RedisConnectionFactory.class); RedisConnection connection = mock(RedisConnection.class); given(factory.getConnection()).willReturn(connection); given(connection.getConfig(anyString())).willReturn(new Properties()); return factory; } }
static RedisConnectionFactory connectionFactory() { RedisConnectionFactory factory = mock(RedisConnectionFactory.class); RedisConnection connection = mock(RedisConnection.class); given(factory.getConnection()).willReturn(connection); given(connection.getConfig(anyString())).willReturn(new Properties()); return factory; } }
static RedisConnectionFactory connectionFactory() { RedisConnectionFactory factory = mock(RedisConnectionFactory.class); RedisConnection connection = mock(RedisConnection.class); given(factory.getConnection()).willReturn(connection); given(connection.getConfig(anyString())).willReturn(new Properties()); return factory; } }
private static RedisConnectionFactory mockRedisConnectionFactory() { RedisConnectionFactory connectionFactory = mock(RedisConnectionFactory.class); RedisConnection connection = mock(RedisConnection.class); given(connectionFactory.getConnection()).willReturn(connection); given(connection.getConfig(anyString())).willReturn(new Properties()); return connectionFactory; }
static RedisConnectionFactory createMockRedisConnection() { RedisConnectionFactory factory = mock(RedisConnectionFactory.class); RedisConnection connection = mock(RedisConnection.class); given(factory.getConnection()).willReturn(connection); given(connection.getConfig(anyString())).willReturn(new Properties()); return factory; }
static RedisConnectionFactory connectionFactory() { RedisConnectionFactory factory = mock(RedisConnectionFactory.class); RedisConnection connection = mock(RedisConnection.class); given(factory.getConnection()).willReturn(connection); given(connection.getConfig(anyString())).willReturn(new Properties()); return factory; } }
@Before public void setup() { given(this.factory.getConnection()).willReturn(this.connection); }
@Before public void setup() { given(this.connectionFactory.getConnection()).willReturn(this.connection); this.initializer = new RedisHttpSessionConfiguration.EnableRedisKeyspaceNotificationsInitializer( this.connectionFactory, new ConfigureNotifyKeyspaceEventsAction()); }