Example usage for org.springframework.data.redis.connection.jedis JedisConnectionFactory JedisConnectionFactory

List of usage examples for org.springframework.data.redis.connection.jedis JedisConnectionFactory JedisConnectionFactory

Introduction

In this page you can find the example usage for org.springframework.data.redis.connection.jedis JedisConnectionFactory JedisConnectionFactory.

Prototype

public JedisConnectionFactory() 

Source Link

Document

Constructs a new JedisConnectionFactory instance with default settings (default connection pooling, no shard information).

Usage

From source file:docs.IndexDocTests.java

@Test
@SuppressWarnings("unused")
public void newRedisOperationsSessionRepository() {
    // tag::new-redisoperationssessionrepository[]
    JedisConnectionFactory factory = new JedisConnectionFactory();
    SessionRepository<? extends ExpiringSession> repository = new RedisOperationsSessionRepository(factory);
    // end::new-redisoperationssessionrepository[]
}

From source file:locksdemo.RedisServer.java

/**
 * Try to obtain and validate a resource. Implementors should either set the
 * {@link #resource} field with a valid resource and return normally, or throw an
 * exception./*from w w w  .  java2 s . c o m*/
 */
protected JedisConnectionFactory obtainResource() throws Exception {
    JedisConnectionFactory resource = new JedisConnectionFactory();
    resource.afterPropertiesSet();
    resource.getConnection().close();
    return resource;
}

From source file:com.company.project.config.DataConfig.java

@Bean
public RedisConnectionFactory redisConnectionFactory() {
    JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory();
    jedisConnectionFactory.setHostName(env.getProperty("redis.host"));
    jedisConnectionFactory.setPort(Integer.valueOf(env.getProperty("redis.port")));
    jedisConnectionFactory.setPassword(env.getProperty("redis.password"));
    jedisConnectionFactory.setUsePool(true);
    return jedisConnectionFactory;
}

From source file:org.springframework.boot.redis.RedisTestServer.java

private JedisConnectionFactory createConnectionFactory() {
    JedisConnectionFactory connectionFactory = new JedisConnectionFactory();
    connectionFactory.afterPropertiesSet();
    testConnection(connectionFactory);//from  w w w  .j a  v a 2 s .  c om
    return connectionFactory;
}

From source file:org.springframework.data.redis.connection.jedis.JedisConnectionFactoryUnitTests.java

/**
 * @throws IOException//w  ww .j a  va 2  s.  c om
 * @see DATAREDIS-315
 */
@Test
public void shouldClostClusterCorrectlyOnFactoryDestruction() throws IOException {

    JedisCluster clusterMock = mock(JedisCluster.class);
    JedisConnectionFactory factory = new JedisConnectionFactory();
    ReflectionTestUtils.setField(factory, "cluster", clusterMock);

    factory.destroy();

    verify(clusterMock, times(1)).close();
}

From source file:org.springframework.data.redis.listener.SubscriptionConnectionTests.java

@Parameters
public static Collection<Object[]> testParams() {
    int port = SettingsUtils.getPort();
    String host = SettingsUtils.getHost();

    // Jedis/*from  w  w w.ja v  a2  s.  c o  m*/
    JedisConnectionFactory jedisConnFactory = new JedisConnectionFactory();
    jedisConnFactory.setPort(port);
    jedisConnFactory.setHostName(host);
    jedisConnFactory.setDatabase(2);
    jedisConnFactory.afterPropertiesSet();

    // Lettuce
    LettuceConnectionFactory lettuceConnFactory = new LettuceConnectionFactory();
    lettuceConnFactory.setClientResources(LettuceTestClientResources.getSharedClientResources());
    lettuceConnFactory.setPort(port);
    lettuceConnFactory.setHostName(host);
    lettuceConnFactory.setDatabase(2);
    lettuceConnFactory.setValidateConnection(true);
    lettuceConnFactory.afterPropertiesSet();

    // SRP
    SrpConnectionFactory srpConnFactory = new SrpConnectionFactory();
    srpConnFactory.setPort(port);
    srpConnFactory.setHostName(host);
    srpConnFactory.afterPropertiesSet();

    // JRedis
    JredisConnectionFactory jRedisConnectionFactory = new JredisConnectionFactory();
    jRedisConnectionFactory.setPort(port);
    jRedisConnectionFactory.setHostName(host);
    jRedisConnectionFactory.setDatabase(2);
    jRedisConnectionFactory.afterPropertiesSet();

    return Arrays.asList(new Object[][] { { jedisConnFactory }, { lettuceConnFactory }, { srpConnFactory },
            { jRedisConnectionFactory } });
}

From source file:org.springframework.integration.redis.inbound.RedisInboundChannelAdapterTests.java

private void testRedisInboundChannelAdapterGuts(int iteration) throws Exception {
    int numToTest = 10;
    String redisChannelName = "testRedisInboundChannelAdapterChannel";
    QueueChannel channel = new QueueChannel();

    JedisConnectionFactory connectionFactory = new JedisConnectionFactory();
    connectionFactory.setPort(7379);/*w  ww  . j ava  2  s . c  o m*/
    connectionFactory.afterPropertiesSet();

    RedisInboundChannelAdapter adapter = new RedisInboundChannelAdapter(connectionFactory);
    adapter.setTopics("testRedisInboundChannelAdapterChannel");
    adapter.setOutputChannel(channel);
    adapter.afterPropertiesSet();
    adapter.start();

    RedisMessageListenerContainer container = waitUntilSubscribed(adapter);

    StringRedisTemplate redisTemplate = new StringRedisTemplate(connectionFactory);
    redisTemplate.afterPropertiesSet();
    for (int i = 0; i < numToTest; i++) {
        String message = "test-" + i + " iteration " + iteration;
        redisTemplate.convertAndSend(redisChannelName, message);
        logger.debug("Sent " + message);
    }
    int counter = 0;
    for (int i = 0; i < numToTest; i++) {
        Message<?> message = channel.receive(5000);
        if (message == null) {
            throw new RuntimeException("Failed to receive message # " + i + " iteration " + iteration);
        }
        assertNotNull(message);
        assertTrue(message.getPayload().toString().startsWith("test-"));
        counter++;
    }
    assertEquals(numToTest, counter);
    adapter.stop();
    container.stop();
    connectionFactory.destroy();
}

From source file:org.springframework.integration.redis.rules.RedisAvailableRule.java

public Statement apply(final Statement base, final FrameworkMethod method, Object target) {
    return new Statement() {

        @Override//from   w w w.j av a  2s  . com
        public void evaluate() throws Throwable {
            RedisAvailable redisAvailable = method.getAnnotation(RedisAvailable.class);
            if (redisAvailable != null) {
                try {

                    JedisConnectionFactory connectionFactory = new JedisConnectionFactory();
                    connectionFactory.setPort(REDIS_PORT);
                    connectionFactory.afterPropertiesSet();
                    connectionFactory.getConnection();
                } catch (Exception e) {
                    if (logger.isWarnEnabled()) {
                        logger.warn(String.format(
                                "Redis is not available on " + "port '%s'. Skipping the test.", REDIS_PORT));
                    }
                    return;
                }
            }
            base.evaluate();
        }
    };

}

From source file:org.springframework.xd.samples.ProductCategoryEnricherTest.java

@Before
public void setUp() {
    JedisConnectionFactory redisConnectionFactory = new JedisConnectionFactory();
    redisConnectionFactory.afterPropertiesSet();

    redisTemplate = new RedisTemplate<>();
    redisTemplate.setConnectionFactory(redisConnectionFactory);
    redisTemplate.setDefaultSerializer(new StringRedisSerializer());
    redisTemplate.afterPropertiesSet();/*from   w  w  w .jav  a 2  s  . c  o m*/
    productCategoryEnricher = new ProductCategoryEnricher(redisTemplate);

}