Search in sources :

Example 1 with StatefulRedisClusterConnection

use of io.lettuce.core.cluster.api.StatefulRedisClusterConnection 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)

Aggregations

LoadingCacheTest (com.alicp.jetcache.LoadingCacheTest)1 AbstractExternalCacheTest (com.alicp.jetcache.test.external.AbstractExternalCacheTest)1 RedisURI (io.lettuce.core.RedisURI)1 RedisClusterClient (io.lettuce.core.cluster.RedisClusterClient)1 StatefulRedisClusterConnection (io.lettuce.core.cluster.api.StatefulRedisClusterConnection)1 Random (java.util.Random)1 Test (org.junit.Test)1