Search in sources :

Example 1 with StatefulRedisMasterSlaveConnection

use of io.lettuce.core.masterslave.StatefulRedisMasterSlaveConnection 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)

Aggregations

LoadingCacheTest (com.alicp.jetcache.LoadingCacheTest)1 AbstractExternalCacheTest (com.alicp.jetcache.test.external.AbstractExternalCacheTest)1 AbstractRedisClient (io.lettuce.core.AbstractRedisClient)1 RedisClient (io.lettuce.core.RedisClient)1 RedisURI (io.lettuce.core.RedisURI)1 StatefulRedisMasterSlaveConnection (io.lettuce.core.masterslave.StatefulRedisMasterSlaveConnection)1 Random (java.util.Random)1 Test (org.junit.Test)1