Search in sources :

Example 1 with RedisClusterClient

use of io.lettuce.core.cluster.RedisClusterClient 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 RedisClusterClient

use of io.lettuce.core.cluster.RedisClusterClient in project jetcache by alibaba.

the class RedisLettuceStarterTest method tests.

@Test
public void tests() throws Exception {
    if (RedisLettuceCacheTest.checkOS()) {
        System.setProperty("spring.profiles.active", "redislettuce-cluster");
    } else {
        System.setProperty("spring.profiles.active", "redislettuce");
    }
    context = SpringApplication.run(RedisLettuceStarterTest.class);
    doTest();
    A bean = context.getBean(A.class);
    bean.test();
    RedisClient t1 = (RedisClient) context.getBean("defaultClient");
    RedisClient t2 = (RedisClient) context.getBean("a1Client");
    Assert.assertNotNull(t1);
    Assert.assertNotNull(t2);
    Assert.assertNotSame(t1, t2);
    AutoConfigureBeans acb = context.getBean(AutoConfigureBeans.class);
    String key = "remote.A1";
    Assert.assertTrue(new LettuceFactory(acb, key, StatefulRedisConnection.class).getObject() instanceof StatefulRedisConnection);
    Assert.assertTrue(new LettuceFactory(acb, key, RedisCommands.class).getObject() instanceof RedisCommands);
    Assert.assertTrue(new LettuceFactory(acb, key, RedisAsyncCommands.class).getObject() instanceof RedisAsyncCommands);
    Assert.assertTrue(new LettuceFactory(acb, key, RedisReactiveCommands.class).getObject() instanceof RedisReactiveCommands);
    if (RedisLettuceCacheTest.checkOS()) {
        key = "remote.A2";
        Assert.assertTrue(new LettuceFactory(acb, key, RedisClusterClient.class).getObject() instanceof RedisClusterClient);
        Assert.assertTrue(new LettuceFactory(acb, key, RedisClusterCommands.class).getObject() instanceof RedisClusterCommands);
        Assert.assertTrue(new LettuceFactory(acb, key, RedisClusterAsyncCommands.class).getObject() instanceof RedisClusterAsyncCommands);
        Assert.assertTrue(new LettuceFactory(acb, key, RedisClusterReactiveCommands.class).getObject() instanceof RedisClusterReactiveCommands);
        key = "remote.A2_slave";
        Assert.assertTrue(new LettuceFactory(acb, key, RedisClusterClient.class).getObject() instanceof RedisClusterClient);
    }
}
Also used : RedisClusterCommands(io.lettuce.core.cluster.api.sync.RedisClusterCommands) StatefulRedisConnection(io.lettuce.core.api.StatefulRedisConnection) RedisClusterAsyncCommands(io.lettuce.core.cluster.api.async.RedisClusterAsyncCommands) RedisClient(io.lettuce.core.RedisClient) RedisCommands(io.lettuce.core.api.sync.RedisCommands) RedisAsyncCommands(io.lettuce.core.api.async.RedisAsyncCommands) RedisClusterReactiveCommands(io.lettuce.core.cluster.api.reactive.RedisClusterReactiveCommands) RedisClusterClient(io.lettuce.core.cluster.RedisClusterClient) RedisReactiveCommands(io.lettuce.core.api.reactive.RedisReactiveCommands) SpringTest(com.alicp.jetcache.test.spring.SpringTest) RedisLettuceCacheTest(com.alicp.jetcache.redis.lettuce.RedisLettuceCacheTest) Test(org.junit.Test)

Example 3 with RedisClusterClient

use of io.lettuce.core.cluster.RedisClusterClient in project curiostack by curioswitch.

the class RedisModule method redisClusterClient.

@Provides
@Singleton
static RedisClusterClient redisClusterClient(RedisConfig config, MeterRegistry registry, Tracing tracing) {
    RedisClusterClient client = RedisClusterClient.create(DefaultClientResources.builder().eventExecutorGroup(CommonPools.workerGroup()).eventLoopGroupProvider(ArmeriaEventLoopGroupProvider.INSTANCE).commandLatencyCollector(new MicrometerCommandLatencyCollector(DEFAULT_METER_ID_PREFIX, registry)).tracing(BraveTracing.create(tracing)).build(), config.getUrl());
    client.setOptions(ClusterClientOptions.builder().validateClusterNodeMembership(false).build());
    return client;
}
Also used : RedisClusterClient(io.lettuce.core.cluster.RedisClusterClient) Singleton(javax.inject.Singleton) Provides(dagger.Provides)

Example 4 with RedisClusterClient

use of io.lettuce.core.cluster.RedisClusterClient in project curiostack by curioswitch.

the class RedisModule method redisClient.

@Provides
@Singleton
static RedisClusterClient redisClient(RedisConfig config, MeterRegistry registry) {
    RedisClusterClient client = RedisClusterClient.create(DefaultClientResources.builder().eventExecutorGroup(CommonPools.workerGroup()).eventLoopGroupProvider(ArmeriaEventLoopGroupProvider.INSTANCE).commandLatencyCollector(new MicrometerCommandLatencyCollector(DEFAULT_METER_ID_PREFIX, registry)).build(), config.getUrl());
    client.setOptions(ClusterClientOptions.builder().validateClusterNodeMembership(false).build());
    return client;
}
Also used : RedisClusterClient(io.lettuce.core.cluster.RedisClusterClient) Singleton(javax.inject.Singleton) Provides(dagger.Provides)

Example 5 with RedisClusterClient

use of io.lettuce.core.cluster.RedisClusterClient in project jetcache by alibaba.

the class LettuceConnectionManagerTest method testCluster.

@Test
public void testCluster() {
    if (!RedisLettuceCacheTest.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));
    LettuceConnectionManager m = LettuceConnectionManager.defaultManager();
    m.init(client, null);
    Assert.assertSame(m.commands(client), m.commands(client));
    Assert.assertSame(m.asyncCommands(client), m.asyncCommands(client));
    Assert.assertSame(m.reactiveCommands(client), m.reactiveCommands(client));
    m.removeAndClose(client);
}
Also used : RedisURI(io.lettuce.core.RedisURI) RedisClusterClient(io.lettuce.core.cluster.RedisClusterClient) Test(org.junit.Test)

Aggregations

RedisClusterClient (io.lettuce.core.cluster.RedisClusterClient)6 Test (org.junit.Test)4 RedisURI (io.lettuce.core.RedisURI)3 LoadingCacheTest (com.alicp.jetcache.LoadingCacheTest)2 AbstractExternalCacheTest (com.alicp.jetcache.test.external.AbstractExternalCacheTest)2 Provides (dagger.Provides)2 Singleton (javax.inject.Singleton)2 RedisLettuceCacheTest (com.alicp.jetcache.redis.lettuce.RedisLettuceCacheTest)1 SpringTest (com.alicp.jetcache.test.spring.SpringTest)1 RedisClient (io.lettuce.core.RedisClient)1 StatefulRedisConnection (io.lettuce.core.api.StatefulRedisConnection)1 RedisAsyncCommands (io.lettuce.core.api.async.RedisAsyncCommands)1 RedisReactiveCommands (io.lettuce.core.api.reactive.RedisReactiveCommands)1 RedisCommands (io.lettuce.core.api.sync.RedisCommands)1 StatefulRedisClusterConnection (io.lettuce.core.cluster.api.StatefulRedisClusterConnection)1 RedisClusterAsyncCommands (io.lettuce.core.cluster.api.async.RedisClusterAsyncCommands)1 RedisClusterReactiveCommands (io.lettuce.core.cluster.api.reactive.RedisClusterReactiveCommands)1 RedisClusterCommands (io.lettuce.core.cluster.api.sync.RedisClusterCommands)1 Random (java.util.Random)1