use of com.lcache.extend.handle.redis.lettuce.config.LettuceConnectSourceConfig in project lcache by long172066912.
the class HotKeyTest method test.
@Test
public void test() {
BaseCacheExecutor baseCacheExecutor = CacheClientFactory.getCacheExecutor("friend", new LettuceConnectSourceConfig()).openLocalCache().setMonitorHotKeyStatisticCapacity(100);
LOGGER.info("Lcache Test hotKey test begin !");
threadPoolExecutor.execute(() -> {
while (true) {
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
time.addAndGet(1);
if (time.get() <= 300) {
LOGGER.info("Lcache Test:" + num);
System.out.println("Lcache Test:" + num);
} else {
LOGGER.info("Lcache Test失败次数:" + errNum);
break;
}
num.set(0);
}
});
final int num1 = 100;
final int num2 = 50;
// 数据准备
new Thread(() -> {
while (true) {
System.out.println("修改数值");
for (int j = 0; j < num2; j++) {
baseCacheExecutor.set("test" + j, j + "", 3600);
}
try {
Thread.sleep(7000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
while (true) {
// 10秒后,降低热key起始值
if (time.get() == 10) {
// System.out.println("设置热key起始值为100");
baseCacheExecutor.setIsOpenHotKeyLocalCache(true);
baseCacheExecutor.setMonitorHotKeyMinValue(100);
}
if (time.get() > 300) {
break;
}
for (int i = 0; i < num1; i++) {
try {
threadPoolExecutor.execute(() -> {
for (int j = 0; j < num2; j++) {
try {
baseCacheExecutor.get("test" + j);
} catch (Exception e) {
errNum.addAndGet(1);
}
num.addAndGet(1);
}
});
} catch (Exception e) {
}
}
}
LOGGER.info("Lcache Test end !");
}
use of com.lcache.extend.handle.redis.lettuce.config.LettuceConnectSourceConfig in project lcache by long172066912.
the class TestRedisCache2 method lockNotUnlockTest.
@Test
public void lockNotUnlockTest() {
BaseCacheExecutor baseCacheExecutor = CacheClientFactory.getCacheExecutor("test", new LettuceConnectSourceConfig());
String lockName = "unLockTest";
for (int i = 0; i < 5; i++) {
int finalI = i;
new Thread(() -> {
try {
RLock lock = null;
try {
lock = baseCacheExecutor.lock(lockName, -1, TimeUnit.SECONDS);
while (true) {
System.out.println("持有锁" + finalI);
try {
Thread.sleep(5000L);
Thread.currentThread().stop();
} catch (InterruptedException e) {
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
baseCacheExecutor.unLock(lock);
System.out.println("释放锁" + finalI);
}
} catch (Exception e) {
e.printStackTrace();
}
}).start();
}
while (true) {
}
}
use of com.lcache.extend.handle.redis.lettuce.config.LettuceConnectSourceConfig in project lcache by long172066912.
the class TestRedisCache2 method testPubSub.
@Test
public void testPubSub() {
for (int p = 0; p < 10; p++) {
int finalP = p;
new Thread(() -> {
BaseCacheExecutor baseCacheExecutor = null;
if (finalP % 2 == 0) {
baseCacheExecutor = CacheClientFactory.getCacheExecutor(CacheConfigModel.newCache("test"), new LettuceConnectSourceConfig());
} else {
baseCacheExecutor = CacheClientFactory.getCacheExecutor(CacheConfigModel.newCache("friend"));
}
int i = 0;
while (true) {
i++;
System.out.println("Lettuce发布消息:" + i);
try {
baseCacheExecutor.publish("test", "test" + i);
Thread.sleep(1000L);
} catch (Exception e) {
e.printStackTrace();
StatefulConnection connectResource = (StatefulConnection) baseCacheExecutor.getConnectResource();
if (!connectResource.isOpen()) {
System.out.println("关闭连接" + connectResource);
baseCacheExecutor.close();
}
baseCacheExecutor.returnConnectResource();
}
}
}).start();
}
new Thread(() -> {
BaseCacheExecutor baseCacheExecutor = null;
baseCacheExecutor = CacheClientFactory.getCacheExecutor(CacheConfigModel.newCache("test"), new LettuceConnectSourceConfig());
baseCacheExecutor.subscribe((message) -> {
System.out.println("Lettuce Local订阅消息:" + message);
}, "test");
}).start();
new Thread(() -> {
BaseCacheExecutor baseCacheExecutor = null;
baseCacheExecutor = CacheClientFactory.getCacheExecutor(CacheConfigModel.newCache("friend"));
baseCacheExecutor.subscribe((message) -> {
System.out.println("Lettuce Dev订阅消息:" + message);
}, "test");
}).start();
while (true) {
}
}
use of com.lcache.extend.handle.redis.lettuce.config.LettuceConnectSourceConfig in project lcache by long172066912.
the class TestRedisCache2 method testLettuceCluster.
@Test
public void testLettuceCluster() {
// LettuceClusterConnectSourceConfig lettuceClusterConnectSourceConfig = new LettuceClusterConnectSourceConfig();
// lettuceClusterConnectSourceConfig.setNodes(new HashSet<>());
// lettuceClusterConnectSourceConfig.getNodes().add(new LettuceConnectSourceConfig("127.0.0.1",30001,null,1500));
// lettuceClusterConnectSourceConfig.getNodes().add(new LettuceConnectSourceConfig("127.0.0.1",30002,null,1500));
// lettuceClusterConnectSourceConfig.getNodes().add(new LettuceConnectSourceConfig("127.0.0.1",30003,null,1500));
// lettuceClusterConnectSourceConfig.getNodes().add(new LettuceConnectSourceConfig("127.0.0.1",30004,null,1500));
// lettuceClusterConnectSourceConfig.getNodes().add(new LettuceConnectSourceConfig("127.0.0.1",30005,null,1500));
// lettuceClusterConnectSourceConfig.getNodes().add(new LettuceConnectSourceConfig("127.0.0.1",30006,null,1500));
BaseCacheExecutor baseCacheExecutor = CacheClientFactory.getCacheExecutor(CacheConfigModel.lettucePool("test"), new LettuceConnectSourceConfig());
new Thread(() -> {
while (true) {
for (int i = 0; i < 100; i++) {
try {
baseCacheExecutor.setex("test" + i, 86400, i + "");
System.out.println("写入" + i);
Thread.sleep(10L);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}).start();
new Thread(() -> {
while (true) {
for (int i = 0; i < 100; i++) {
try {
System.out.println("读取" + baseCacheExecutor.get("test" + i));
} catch (Exception e) {
e.printStackTrace();
}
}
}
}).start();
while (true) {
}
}
use of com.lcache.extend.handle.redis.lettuce.config.LettuceConnectSourceConfig in project lcache by long172066912.
the class TestRedisCache2 method testZaddLua.
@Test
public void testZaddLua() {
BaseCacheExecutor baseCacheExecutor = CacheClientFactory.getCacheExecutor("test", new LettuceConnectSourceConfig());
String key = "zaddIfKeyExistsTest";
baseCacheExecutor.del(key);
System.out.println(baseCacheExecutor.zaddIfKeyExists(key, 1, "a", 3600));
System.out.println(baseCacheExecutor.zrange(key, 0, -1));
System.out.println(baseCacheExecutor.zadd(key, 2, "b", 3600));
System.out.println(baseCacheExecutor.zaddIfKeyExists(key, 3, "c", 3600));
System.out.println(baseCacheExecutor.zrange(key, 0, -1));
}
Aggregations