当前位置:网站首页>Redis cluster simulated message queue
Redis cluster simulated message queue
2022-07-05 19:41:00 【Mysterious gate】
- preparation : install redis And set up clusters
- IDEA Create a new project and write a test class RedisTest, Add cluster environment configuration code
private Jedis jedis;
private JedisCluster jedisCluster;
@Before
public void connectionRedis(){
jedis = new Jedis("192.168.1.118",6379);
//jedis = new Jedis("192.168.1.20",6382);
//jedis.auth("123456");
HostAndPort hp1 = new HostAndPort("192.168.1.20", 6381);
HostAndPort hp2 = new HostAndPort("192.168.1.20", 6382);
HostAndPort hp3 = new HostAndPort("192.168.1.20", 6383);
HostAndPort hp4 = new HostAndPort("192.168.1.20", 6384);
HostAndPort hp5 = new HostAndPort("192.168.1.20", 6385);
HostAndPort hp6 = new HostAndPort("192.168.1.20", 6386);
Set<HostAndPort> hostAndPortSet = new HashSet<>();
hostAndPortSet.add(hp1);
hostAndPortSet.add(hp2);
hostAndPortSet.add(hp3);
hostAndPortSet.add(hp4);
hostAndPortSet.add(hp5);
hostAndPortSet.add(hp6);
jedisCluster = new JedisCluster(hostAndPortSet);
}
- Add a test method for joining the team
// Cluster mode test queue operation
@Test
public void testEnterQueue(){
jedisCluster.lpush("queue-1"," Thank you for your support ");
}
- Add team test method
// The cluster mode tests the team operation
@Test
public void testOutQueue() throws InterruptedException{
Thread t = new Thread("thread-getmsg"){
@Override
public void run() {
while(true){
String s = jedisCluster.rpop("queue-1");
if(null==s){
try {
Thread.sleep(3*1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println(s);
}
}
};
t.start();
t.join();// Ensure that the main thread ends only after the sub thread ends
}
You can see if there is no message in the message queue , Then the thread sleeps 3 Seconds to perform , This can effectively prevent CPU Idle
边栏推荐
- 太牛了,看这篇足矣了
- Debezium系列之:解析默认值字符集
- [OBS] qstring's UTF-8 Chinese conversion to blog printing UTF-8 char*
- 使用easyexcel模板导出的两个坑(Map空数据列错乱和不支持嵌套对象)
- PG basics -- Logical Structure Management (user and permission management)
- 【obs】libobs-winrt :CreateDispatcherQueueController
- Is it safe for China Galaxy Securities to open an account? Securities account opening
- Worthy of being a boss, byte Daniel spent eight months on another masterpiece
- 强化学习-学习笔记4 | Actor-Critic
- 司空见惯 - 英雄扫雷鼠
猜你喜欢
How to convert word into PDF? Word to PDF simple way to share!
What do software test engineers do? How about the prospect of treatment?
Mysql如何对json数据进行查询及修改
【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
Password reset of MariaDB root user and ordinary user
力扣 1200. 最小绝对差
成功入职百度月薪35K,2022Android开发面试解答
软件测试是干什么的?学习有啥要求?
Recommended collection, my Tencent Android interview experience sharing
微波雷达感应模块技术,实时智能检测人体存在,静止微小动静感知
随机推荐
成功入职百度月薪35K,2022Android开发面试解答
再忙不能忘安全
Android interview, Android audio and video development
shell编程基础(第9篇:循环)
PHP uses ueditor to upload pictures and add watermarks
爬虫练习题(二)
Mysql如何对json数据进行查询及修改
MMO project learning 1: preheating
MySql中的longtext字段的返回问题及解决
测试的核心价值到底是什么?
Tutoriel de téléchargement et d'installation du progiciel fuzor 2020
5 years of experience, 27 days of Android programmer interview, 2022 programmer advanced classic
[OBS] qstring's UTF-8 Chinese conversion to blog printing UTF-8 char*
acm入门day1
如何在2022年更明智地应用智能合约?
Is it safe to open a mobile stock account? Is it reliable?
What is the function of okcc call center
third-party dynamic library (libcudnn.so) that Paddle depends on is not configured correctl
Do you know several assertion methods commonly used by JMeter?
全网最全的低代码/无代码平台盘点:简道云、伙伴云、明道云、轻流、速融云、集简云、Treelab、钉钉·宜搭、腾讯云·微搭、智能云·爱速搭、百数云