List of usage examples for org.springframework.data.redis.connection RedisConnectionFactory getConnection
RedisConnection getConnection();
From source file:docs.http.AbstractHttpSessionListenerTests.java
static RedisConnectionFactory createMockRedisConnection() { RedisConnectionFactory factory = mock(RedisConnectionFactory.class); RedisConnection connection = mock(RedisConnection.class); given(factory.getConnection()).willReturn(connection); return factory; }
From source file:com.gopivotal.cloudfoundry.test.core.RedisUtils.java
public String checkAccess(RedisConnectionFactory redisConnectionFactory) { RedisConnection connection = null;//from ww w. j a va 2 s . c om try { connection = redisConnectionFactory.getConnection(); connection.echo("hello".getBytes()); return "ok"; } catch (Exception e) { return "failed with " + e.getMessage(); } finally { try { if (connection != null) { connection.close(); } } catch (Exception e) { return "Redis connection close failed with " + e.getMessage(); } } }
From source file:org.springframework.boot.testsupport.rule.RedisTestServer.java
private void testConnection(RedisConnectionFactory connectionFactory) { connectionFactory.getConnection().close(); }
From source file:org.springframework.data.redis.core.RedisConnectionUtils.java
/** * Gets a Redis connection. Is aware of and will return any existing corresponding connections bound to the current * thread, for example when using a transaction manager. Will create a new Connection otherwise, if * {@code allowCreate} is <tt>true</tt>. * /*from w w w . j a v a2 s . c o m*/ * @param factory connection factory for creating the connection * @param allowCreate whether a new (unbound) connection should be created when no connection can be found for the * current thread * @param bind binds the connection to the thread, in case one was created * @param enableTransactionSupport * @return an active Redis connection */ public static RedisConnection doGetConnection(RedisConnectionFactory factory, boolean allowCreate, boolean bind, boolean enableTransactionSupport) { Assert.notNull(factory, "No RedisConnectionFactory specified"); RedisConnectionHolder connHolder = (RedisConnectionHolder) TransactionSynchronizationManager .getResource(factory); if (connHolder != null) { if (enableTransactionSupport) { potentiallyRegisterTransactionSynchronisation(connHolder, factory); } return connHolder.getConnection(); } if (!allowCreate) { throw new IllegalArgumentException("No connection found and allowCreate = false"); } if (log.isDebugEnabled()) { log.debug("Opening RedisConnection"); } RedisConnection conn = factory.getConnection(); if (bind) { RedisConnection connectionToBind = conn; if (enableTransactionSupport && isActualNonReadonlyTransactionActive()) { connectionToBind = createConnectionProxy(conn, factory); } connHolder = new RedisConnectionHolder(connectionToBind); TransactionSynchronizationManager.bindResource(factory, connHolder); if (enableTransactionSupport) { potentiallyRegisterTransactionSynchronisation(connHolder, factory); } return connHolder.getConnection(); } return conn; }