Search in sources :

Example 1 with RedisClient

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

the class RedisLettuceCacheFailTest method setup.

@BeforeEach
public void setup() {
    client = mock(RedisClient.class);
    StatefulRedisConnection connection = mock(StatefulRedisConnection.class);
    asyncCommands = mock(RedisAsyncCommands.class);
    when(client.connect((JetCacheCodec) any())).thenReturn(connection);
    when(connection.sync()).thenReturn(null);
    when(connection.async()).thenReturn(asyncCommands);
    cache = RedisLettuceCacheBuilder.createRedisLettuceCacheBuilder().redisClient(client).keyPrefix("fail_test").buildCache();
}
Also used : RedisClient(io.lettuce.core.RedisClient) RedisAsyncCommands(io.lettuce.core.api.async.RedisAsyncCommands) StatefulRedisConnection(io.lettuce.core.api.StatefulRedisConnection) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with RedisClient

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

the class LettuceConnectionManagerTest method test.

@Test
public void test() {
    RedisClient client = RedisClient.create("redis://127.0.0.1");
    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 : RedisClient(io.lettuce.core.RedisClient) Test(org.junit.Test)

Example 3 with RedisClient

use of io.lettuce.core.RedisClient 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 4 with RedisClient

use of io.lettuce.core.RedisClient 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 5 with RedisClient

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

Aggregations

RedisClient (io.lettuce.core.RedisClient)11 Test (org.junit.Test)6 LoadingCacheTest (com.alicp.jetcache.LoadingCacheTest)4 AbstractExternalCacheTest (com.alicp.jetcache.test.external.AbstractExternalCacheTest)4 AbstractRedisClient (io.lettuce.core.AbstractRedisClient)4 RedisURI (io.lettuce.core.RedisURI)3 Random (java.util.Random)3 StatefulRedisConnection (io.lettuce.core.api.StatefulRedisConnection)2 RedisAsyncCommands (io.lettuce.core.api.async.RedisAsyncCommands)2 Cache (com.alicp.jetcache.Cache)1 RedisLettuceCacheTest (com.alicp.jetcache.redis.lettuce.RedisLettuceCacheTest)1 SpringTest (com.alicp.jetcache.test.spring.SpringTest)1 RedisReactiveCommands (io.lettuce.core.api.reactive.RedisReactiveCommands)1 RedisCommands (io.lettuce.core.api.sync.RedisCommands)1 RedisClusterClient (io.lettuce.core.cluster.RedisClusterClient)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 StatefulRedisMasterSlaveConnection (io.lettuce.core.masterslave.StatefulRedisMasterSlaveConnection)1 DateTime (org.joda.time.DateTime)1