Search in sources :

Example 1 with RedisURI

use of io.lettuce.core.RedisURI in project jetcache by alibaba.

the class RedisLettuceCacheTest method testCluster2.

@Test
public void testCluster2() throws Exception {
    if (!checkOS()) {
        return;
    }
    RedisURI node1 = RedisURI.create("127.0.0.1", 7000);
    RedisURI node2 = RedisURI.create("127.0.0.1", 7001);
    RedisURI node3 = RedisURI.create("127.0.0.1", 7002);
    RedisClusterClient client = RedisClusterClient.create(Arrays.asList(node1, node2, node3));
    StatefulRedisClusterConnection con = client.connect(new JetCacheCodec());
    con.setReadFrom(ReadFrom.SLAVE_PREFERRED);
    cache = RedisLettuceCacheBuilder.createRedisLettuceCacheBuilder().redisClient(client).connection(con).keyPrefix(new Random().nextInt() + "").buildCache();
    cache.put("K1", "V1");
    Thread.sleep(100);
    Assert.assertEquals("V1", cache.get("K1"));
}
Also used : StatefulRedisClusterConnection(io.lettuce.core.cluster.api.StatefulRedisClusterConnection) Random(java.util.Random) RedisURI(io.lettuce.core.RedisURI) RedisClusterClient(io.lettuce.core.cluster.RedisClusterClient) LoadingCacheTest(com.alicp.jetcache.LoadingCacheTest) AbstractExternalCacheTest(com.alicp.jetcache.test.external.AbstractExternalCacheTest) Test(org.junit.Test)

Example 2 with RedisURI

use of io.lettuce.core.RedisURI in project jetcache by alibaba.

the class RedisLettuceCacheTest method testSentinel2.

@Test
public void testSentinel2() throws Exception {
    RedisURI redisUri = RedisURI.Builder.sentinel("127.0.0.1", 26379, "mymaster").withSentinel("127.0.0.1", 26380).withSentinel("127.0.0.1", 26381).build();
    RedisClient client = RedisClient.create();
    StatefulRedisMasterSlaveConnection con = MasterSlave.connect(client, new JetCacheCodec(), redisUri);
    con.setReadFrom(ReadFrom.SLAVE_PREFERRED);
    cache = RedisLettuceCacheBuilder.createRedisLettuceCacheBuilder().redisClient(client).connection(con).keyPrefix(new Random().nextInt() + "").buildCache();
    cache.put("K1", "V1");
    Thread.sleep(100);
    Assert.assertEquals("V1", cache.get("K1"));
}
Also used : RedisClient(io.lettuce.core.RedisClient) AbstractRedisClient(io.lettuce.core.AbstractRedisClient) Random(java.util.Random) StatefulRedisMasterSlaveConnection(io.lettuce.core.masterslave.StatefulRedisMasterSlaveConnection) RedisURI(io.lettuce.core.RedisURI) LoadingCacheTest(com.alicp.jetcache.LoadingCacheTest) AbstractExternalCacheTest(com.alicp.jetcache.test.external.AbstractExternalCacheTest) Test(org.junit.Test)

Example 3 with RedisURI

use of io.lettuce.core.RedisURI in project jetcache by alibaba.

the class RedisLettuceCacheTest method testSentinel.

@Test
public void testSentinel() throws Exception {
    RedisURI redisUri = RedisURI.Builder.sentinel("127.0.0.1", 26379, "mymaster").withSentinel("127.0.0.1", 26380).withSentinel("127.0.0.1", 26381).build();
    RedisClient client = RedisClient.create(redisUri);
    test(client, null);
}
Also used : RedisClient(io.lettuce.core.RedisClient) AbstractRedisClient(io.lettuce.core.AbstractRedisClient) RedisURI(io.lettuce.core.RedisURI) LoadingCacheTest(com.alicp.jetcache.LoadingCacheTest) AbstractExternalCacheTest(com.alicp.jetcache.test.external.AbstractExternalCacheTest) Test(org.junit.Test)

Example 4 with RedisURI

use of io.lettuce.core.RedisURI in project pinpoint by naver.

the class RedisClusterClientConstructorInterceptor method getEndPoint.

private String getEndPoint(Iterable<RedisURI> redisURIs) {
    final List<String> endPoints = new ArrayList<>();
    for (RedisURI redisURI : redisURIs) {
        final String hostAndPort = HostAndPort.toHostAndPortString(redisURI.getHost(), redisURI.getPort());
        endPoints.add(hostAndPort);
    }
    return endPoints.isEmpty() ? null : endPoints.toString();
}
Also used : RedisURI(io.lettuce.core.RedisURI) ArrayList(java.util.ArrayList)

Example 5 with RedisURI

use of io.lettuce.core.RedisURI in project verify-hub by alphagov.

the class PolicyConfigurationBuilder method build.

public PolicyConfiguration build() {
    SessionStoreConfiguration sessionStoreConfiguration = mock(SessionStoreConfiguration.class);
    when(sessionStoreConfiguration.getRedisConfiguration()).thenReturn(new RedisConfiguration() {

        @Override
        public Long getRecordTTL() {
            return 3600L;
        }

        @Override
        public RedisURI getUri() {
            return new RedisURI("localhost", redisPort, java.time.Duration.ofSeconds(1));
        }
    });
    return new TestPolicyConfiguration(new JerseyClientConfiguration(), serviceInfo, mock(ClientTrustStoreConfiguration.class), sessionStoreConfiguration, timeoutPeriod, Duration.minutes(1), Duration.minutes(15));
}
Also used : JerseyClientConfiguration(io.dropwizard.client.JerseyClientConfiguration) RedisURI(io.lettuce.core.RedisURI) SessionStoreConfiguration(uk.gov.ida.hub.policy.configuration.SessionStoreConfiguration) RedisConfiguration(uk.gov.ida.hub.policy.configuration.RedisConfiguration) ClientTrustStoreConfiguration(uk.gov.ida.truststore.ClientTrustStoreConfiguration)

Aggregations

RedisURI (io.lettuce.core.RedisURI)10 Test (org.junit.Test)5 LoadingCacheTest (com.alicp.jetcache.LoadingCacheTest)4 AbstractExternalCacheTest (com.alicp.jetcache.test.external.AbstractExternalCacheTest)4 RedisClient (io.lettuce.core.RedisClient)3 RedisClusterClient (io.lettuce.core.cluster.RedisClusterClient)3 AbstractRedisClient (io.lettuce.core.AbstractRedisClient)2 Random (java.util.Random)2 EndPointAccessor (com.navercorp.pinpoint.plugin.redis.lettuce.EndPointAccessor)1 JerseyClientConfiguration (io.dropwizard.client.JerseyClientConfiguration)1 StatefulRedisClusterConnection (io.lettuce.core.cluster.api.StatefulRedisClusterConnection)1 StatefulRedisMasterSlaveConnection (io.lettuce.core.masterslave.StatefulRedisMasterSlaveConnection)1 ArrayList (java.util.ArrayList)1 DateTime (org.joda.time.DateTime)1 RedisConfiguration (uk.gov.ida.hub.policy.configuration.RedisConfiguration)1 SessionStoreConfiguration (uk.gov.ida.hub.policy.configuration.SessionStoreConfiguration)1 SessionId (uk.gov.ida.hub.policy.domain.SessionId)1 State (uk.gov.ida.hub.policy.domain.State)1 SessionStoreRedisCodec (uk.gov.ida.hub.policy.redis.SessionStoreRedisCodec)1 RedisSessionStore (uk.gov.ida.hub.policy.session.RedisSessionStore)1