当前位置:网站首页>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
边栏推荐
猜你喜欢

软件测试工程师是做什么的?待遇前景怎么样?

集合

【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法

Tutoriel de téléchargement et d'installation du progiciel fuzor 2020

全网最全的低代码/无代码平台盘点:简道云、伙伴云、明道云、轻流、速融云、集简云、Treelab、钉钉·宜搭、腾讯云·微搭、智能云·爱速搭、百数云

40000 word Wenshuo operator new & operator delete

The city chain technology Digital Innovation Strategy Summit was successfully held

2022 the latest big company Android interview real problem analysis, Android development will be able to technology

C#应用程序界面开发基础——窗体控制(5)——分组类控件
![[FAQ] summary of common causes and solutions of Huawei account service error 907135701](/img/1d/0e716533237c0e4463f5d6357395bd.png)
[FAQ] summary of common causes and solutions of Huawei account service error 907135701
随机推荐
id选择器和类选择器的区别
Zhongang Mining: analysis of the current market supply situation of the global fluorite industry in 2022
建议收藏,我的腾讯Android面试经历分享
【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
Django uses mysqlclient service to connect and write to the database
shell编程基础(第9篇:循环)
不愧是大佬,字节大牛耗时八个月又一力作
vagrant2.2.6支持virtualbox6.1版本
IFD-x 微型红外成像仪(模块)关于温度测量和成像精度的关系
Hiengine: comparable to the local cloud native memory database engine
word如何转换成pdf?word转pdf简单的方法分享!
Bitcoinwin (BCW)受邀参加Hanoi Traders Fair 2022
Gstreamer中的task
力扣 1200. 最小绝对差
【合集- 行业解决方案】如何搭建高性能的数据加速与数据编排平台
[OBS] qstring's UTF-8 Chinese conversion to blog printing UTF-8 char*
司空见惯 - 英雄扫雷鼠
Reptile exercises (II)
Debezium系列之:记录mariadb数据库删除多张临时表debezium解析到的消息以及解决方法
MMO項目學習一:預熱