Search in sources :

Example 16 with LettuceConnectSourceConfig

use of com.lcache.extend.handle.redis.lettuce.config.LettuceConnectSourceConfig in project lcache by long172066912.

the class TestRedisCache2 method asyncTest.

@Test
public void asyncTest() {
    BaseCacheExecutor baseCacheExecutor = CacheClientFactory.getCacheExecutor("test", new LettuceConnectSourceConfig());
    baseCacheExecutor.del("lincr1");
    baseCacheExecutor.async().incr("lincr1", 60).thenRun(() -> baseCacheExecutor.asyncL().incr("lincr1"));
    assertEquals(2, Long.parseLong(baseCacheExecutor.get("lincr1")));
    System.out.println("asyncIncr 通过 !");
    baseCacheExecutor.set("test", "aaa", 60);
    baseCacheExecutor.asyncL().getset("test", "bbb").thenRun(() -> baseCacheExecutor.asyncL().getset("test", "ccc").thenRun(() -> assertEquals("ccc", baseCacheExecutor.get("test"))));
    System.out.println("asyncTest 通过 !");
}
Also used : BaseCacheExecutor(com.lcache.core.BaseCacheExecutor) LettuceConnectSourceConfig(com.lcache.extend.handle.redis.lettuce.config.LettuceConnectSourceConfig) Test(org.junit.Test)

Example 17 with LettuceConnectSourceConfig

use of com.lcache.extend.handle.redis.lettuce.config.LettuceConnectSourceConfig in project lcache by long172066912.

the class TestRedisCache2 method evalZadd.

@Test
public void evalZadd() {
    new Thread(() -> {
        BaseCacheExecutor jedis = CacheClientFactory.getCacheExecutor(CacheConfigModel.jedisPool("test"), new JedisConnectSourceConfig());
        // zset批量判断是否存
        String jzsetKey = "jzset:test:1";
        jedis.del(jzsetKey);
        while (true) {
            try {
                jedis.zadd(jzsetKey, ImmutableMap.of("a", (double) 1, "b", (double) 2, "c", (double) 3), 3600);
                jedis.zaddIfKeyExists(jzsetKey, 4, "e", 3600);
                Map<String, Double> score = jedis.zscoreBatch(jzsetKey, Arrays.asList("a", "b", "c", "e"));
                System.out.println("jedis : " + JSON.toJSONString(score));
                Thread.sleep(500L);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }).start();
    BaseCacheExecutor baseCacheExecutor = CacheClientFactory.getCacheExecutor("test", new LettuceConnectSourceConfig());
    // zset批量判断是否存
    String zsetKey = "lzset:test:1";
    baseCacheExecutor.del(zsetKey);
    while (true) {
        try {
            baseCacheExecutor.zadd(zsetKey, ImmutableMap.of("a", (double) 1, "b", (double) 2, "c", (double) 3), 3600);
            baseCacheExecutor.zaddIfKeyExists(zsetKey, 4, "e", 3600);
            Map<String, Double> score = baseCacheExecutor.zscoreBatch(zsetKey, Arrays.asList("a", "b", "c", "e"));
            System.out.println("lettuce : " + JSON.toJSONString(score));
            Thread.sleep(500L);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : JedisConnectSourceConfig(com.lcache.extend.handle.redis.jedis.config.JedisConnectSourceConfig) BaseCacheExecutor(com.lcache.core.BaseCacheExecutor) LettuceConnectSourceConfig(com.lcache.extend.handle.redis.lettuce.config.LettuceConnectSourceConfig) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

LettuceConnectSourceConfig (com.lcache.extend.handle.redis.lettuce.config.LettuceConnectSourceConfig)17 Test (org.junit.Test)13 BaseCacheExecutor (com.lcache.core.BaseCacheExecutor)12 ExecutionException (java.util.concurrent.ExecutionException)8 ArrayList (java.util.ArrayList)6 JedisConnectSourceConfig (com.lcache.extend.handle.redis.jedis.config.JedisConnectSourceConfig)5 ImmutableMap (com.google.common.collect.ImmutableMap)3 CacheConfigModel (com.lcache.core.model.CacheConfigModel)3 PipelineCmd (com.lcache.extend.handle.pipeline.PipelineCmd)3 PipelineGet (com.lcache.extend.handle.pipeline.PipelineGet)3 PipelineZremRangeByScore (com.lcache.extend.handle.pipeline.PipelineZremRangeByScore)3 RedisURI (io.lettuce.core.RedisURI)3 RedisClusterClient (io.lettuce.core.cluster.RedisClusterClient)3 DefaultClientResources (io.lettuce.core.resource.DefaultClientResources)3 List (java.util.List)3 Map (java.util.Map)3 RLock (org.redisson.api.RLock)3 JSON (com.alibaba.fastjson.JSON)2 CacheClientFactory (com.lcache.client.CacheClientFactory)2 LcacheCaffeineLocalCache (com.lcache.core.cache.localcache.LcacheCaffeineLocalCache)2