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());
}
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())));
}
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();
}
}
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();
}
}
}
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();
}
}
Aggregations