Search in sources :

Example 1 with LettuceConnectSourceConfig

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

the class assertTest method getExecutor.

@Test
public void getExecutor() {
    assertEquals(jedis, CacheClientFactory.getCacheExecutor(new CacheConfigModel().setClientType(RedisClientConstants.JEDIS).setConnectTypeEnum(ConnectTypeEnum.POOL).setCacheType("test"), new JedisConnectSourceConfig()));
    assertEquals(lettuce, CacheClientFactory.getCacheExecutor(new CacheConfigModel().setClientType(RedisClientConstants.LETTUCE).setConnectTypeEnum(ConnectTypeEnum.SIMPLE).setCacheType("test1"), new LettuceConnectSourceConfig()));
    assertEquals(jedis, CacheClientFactory.builder().cacheType("test").clientType(RedisClientConstants.JEDIS).connectType(ConnectTypeEnum.POOL).cacheConfig(new JedisConnectSourceConfig()).build());
    assertEquals(lettuce, CacheClientFactory.builder().cacheType("test1").clientType(RedisClientConstants.LETTUCE).connectType(ConnectTypeEnum.SIMPLE).cacheConfig(new LettuceConnectSourceConfig()).build());
}
Also used : JedisConnectSourceConfig(com.lcache.extend.handle.redis.jedis.config.JedisConnectSourceConfig) LettuceConnectSourceConfig(com.lcache.extend.handle.redis.lettuce.config.LettuceConnectSourceConfig) CacheConfigModel(com.lcache.core.model.CacheConfigModel) Test(org.junit.Test)

Example 2 with LettuceConnectSourceConfig

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

the class TestRedisCache2 method testRedisson.

@Test
public void testRedisson() {
    BaseCacheExecutor baseCacheExecutor = CacheClientFactory.getCacheExecutor("test", new LettuceConnectSourceConfig());
    RedissonClient redissonClient = baseCacheExecutor.getRedissonClient();
    // zset批量判断是否存
    String zsetKey = "zset:test:1";
    baseCacheExecutor.zadd(zsetKey, ImmutableMap.of("a", (double) 1, "b", (double) 2, "c", (double) 3), 3600);
    System.out.println(baseCacheExecutor.zscore(zsetKey, "a"));
    // redissonClient.getScoredSortedSet(zsetKey).addAll(ImmutableMap.of("d",(double) 4));
    List<String> strings = Arrays.asList("a", "b", "d");
    RScoredSortedSet<String> scoredSortedSet = redissonClient.getScoredSortedSet(zsetKey, StringCodec.INSTANCE);
    List<Double> score = scoredSortedSet.getScore(strings);
    System.out.println(JSON.toJSONString(score.stream().filter(e -> null != e).map(e -> e.toString()).collect(Collectors.toList())));
}
Also used : RScoredSortedSet(org.redisson.api.RScoredSortedSet) PipelineZremRangeByScore(com.lcache.extend.handle.pipeline.PipelineZremRangeByScore) Arrays(java.util.Arrays) PipelineGet(com.lcache.extend.handle.pipeline.PipelineGet) StringCodec(org.redisson.client.codec.StringCodec) LettuceConnectSourceConfig(com.lcache.extend.handle.redis.lettuce.config.LettuceConnectSourceConfig) CompletableFuture(java.util.concurrent.CompletableFuture) JedisConnectSourceConfig(com.lcache.extend.handle.redis.jedis.config.JedisConnectSourceConfig) StatefulConnection(io.lettuce.core.api.StatefulConnection) ArrayList(java.util.ArrayList) RLock(org.redisson.api.RLock) Map(java.util.Map) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) RedissonClient(org.redisson.api.RedissonClient) CacheClientFactory(com.lcache.client.CacheClientFactory) CacheConfigModel(com.lcache.core.model.CacheConfigModel) LcacheCaffeineLocalCache(com.lcache.core.cache.localcache.LcacheCaffeineLocalCache) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test) Collectors(java.util.stream.Collectors) PipelineCmd(com.lcache.extend.handle.pipeline.PipelineCmd) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) JSON(com.alibaba.fastjson.JSON) BaseCacheExecutor(com.lcache.core.BaseCacheExecutor) Assert.assertEquals(org.junit.Assert.assertEquals) RedissonClient(org.redisson.api.RedissonClient) BaseCacheExecutor(com.lcache.core.BaseCacheExecutor) LettuceConnectSourceConfig(com.lcache.extend.handle.redis.lettuce.config.LettuceConnectSourceConfig) Test(org.junit.Test)

Example 3 with LettuceConnectSourceConfig

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

the class TestRedisCache2 method testList.

@Test
public void testList() {
    BaseCacheExecutor baseCacheExecutor = CacheClientFactory.getCacheExecutor(CacheConfigModel.lettucePool("test"), new LettuceConnectSourceConfig());
    Thread a = new Thread(() -> {
        int i = 0;
        while (true) {
            i++;
            System.out.println("Lettuce发布消息:" + i);
            try {
                baseCacheExecutor.lpush("testList", "test" + i, 3600);
            } catch (Exception e) {
                e.printStackTrace();
            }
            try {
                Thread.sleep(1000L);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    Thread b = new Thread(() -> {
        while (true) {
            System.out.println(baseCacheExecutor.brpop(1, "testList"));
        }
    });
    new Thread(() -> {
        while (true) {
            System.out.println(baseCacheExecutor.get("test"));
        }
    }).start();
    a.start();
    b.start();
    try {
        a.join();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : BaseCacheExecutor(com.lcache.core.BaseCacheExecutor) LettuceConnectSourceConfig(com.lcache.extend.handle.redis.lettuce.config.LettuceConnectSourceConfig) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 4 with LettuceConnectSourceConfig

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

the class TestRedisCache2 method bzpopTest.

@Test
public void bzpopTest() {
    BaseCacheExecutor baseCacheExecutor = CacheClientFactory.getCacheExecutor("test", new LettuceConnectSourceConfig());
    BaseCacheExecutor baseCacheExecutor1 = CacheClientFactory.getCacheExecutor("test1", new LettuceConnectSourceConfig());
    BaseCacheExecutor baseCacheExecutor2 = CacheClientFactory.getCacheExecutor("test2", new LettuceConnectSourceConfig());
    String key = "bzpop:test";
    baseCacheExecutor.del(key);
    new Thread(() -> {
        int i = 0;
        while (true) {
            try {
                i++;
                baseCacheExecutor.zadd(key, i, i + "", 3600);
                Thread.sleep(10L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }).start();
    new Thread(() -> {
        while (true) {
            try {
                System.out.println("zpopmax : " + baseCacheExecutor1.zpopmax(key));
                System.out.println("zpopmax+count : " + baseCacheExecutor1.zpopmax(key, 2));
                System.out.println("bzpopmax : " + baseCacheExecutor1.bzpopmax(1, key));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }).start();
    new Thread(() -> {
        while (true) {
            try {
                System.out.println("zpopmin : " + baseCacheExecutor2.zpopmin(key));
                System.out.println("zpopmin+count : " + baseCacheExecutor2.zpopmin(key, 2));
                System.out.println("bzpopmin : " + baseCacheExecutor2.bzpopmin(1, key));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }).start();
    while (true) {
        try {
            System.out.println("zcard : " + baseCacheExecutor.zcard(key));
            Thread.sleep(50L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
Also used : BaseCacheExecutor(com.lcache.core.BaseCacheExecutor) LettuceConnectSourceConfig(com.lcache.extend.handle.redis.lettuce.config.LettuceConnectSourceConfig) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 5 with LettuceConnectSourceConfig

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

the class TestRedisCache2 method testExpireBatch.

@Test
public void testExpireBatch() {
    BaseCacheExecutor baseCacheExecutor = CacheClientFactory.getCacheExecutor("test", new LettuceConnectSourceConfig());
    baseCacheExecutor.set("a", "a", 60);
    baseCacheExecutor.set("b", "b", 60);
    try {
        String s = baseCacheExecutor.async().expireBatch(30, "a", "b").get();
        System.out.println(s);
        Map<String, Boolean> res = JSON.parseObject(s, Map.class);
        System.out.println(res.get("a"));
        System.out.println(baseCacheExecutor.ttl("a"));
        System.out.println(baseCacheExecutor.ttl("b"));
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
}
Also used : BaseCacheExecutor(com.lcache.core.BaseCacheExecutor) LettuceConnectSourceConfig(com.lcache.extend.handle.redis.lettuce.config.LettuceConnectSourceConfig) 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