当前位置:网站首页>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
边栏推荐
- 什么是面上项目
- Common operators and operator priority
- 【合集- 行业解决方案】如何搭建高性能的数据加速与数据编排平台
- 成功入职百度月薪35K,2022Android开发面试解答
- 关于 Notion-Like 工具的反思和畅想
- Notion 类生产力工具如何选择?Notion 、FlowUs 、Wolai 对比评测
- Which securities company is better and which platform is safer for mobile account opening
- JAD installation, configuration and integration idea
- PG基础篇--逻辑结构管理(用户及权限管理)
- The problem of returning the longtext field in MySQL and its solution
猜你喜欢

Explain in detail the functions and underlying implementation logic of the groups sets statement in SQL

word如何转换成pdf?word转pdf简单的方法分享!

Do you know several assertion methods commonly used by JMeter?

5 years of experience, 27 days of Android programmer interview, 2022 programmer advanced classic
完爆面试官,一线互联网企业高级Android工程师面试题大全

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

Hiengine: comparable to the local cloud native memory database engine

再忙不能忘安全

Debezium系列之:记录mariadb数据库删除多张临时表debezium解析到的消息以及解决方法

大厂面试必备技能,2022Android不死我不倒
随机推荐
【obs】libobs-winrt :CreateDispatcherQueueController
Successful entry into Baidu, 35K monthly salary, 2022 Android development interview answer
UWB ultra wideband positioning technology, real-time centimeter level high-precision positioning application, ultra wideband transmission technology
Debezium系列之:记录mariadb数据库删除多张临时表debezium解析到的消息以及解决方法
Bitcoinwin (BCW)受邀参加Hanoi Traders Fair 2022
HAC集群修改管理员用户密码
PHP uses ueditor to upload pictures and add watermarks
Fuzor 2020 software installation package download and installation tutorial
JAD installation, configuration and integration idea
城链科技数字化创新战略峰会圆满召开
The relationship between temperature measurement and imaging accuracy of ifd-x micro infrared imager (module)
如何实现游戏中的在线计时器和离线计时器
Is it safe to open a mobile stock account? Is it reliable?
力扣 729. 我的日程安排表 I
How to convert word into PDF? Word to PDF simple way to share!
【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
测试的核心价值到底是什么?
C#应用程序界面开发基础——窗体控制(5)——分组类控件
成功入职百度月薪35K,2022Android开发面试解答
Postman核心功能解析-参数化和测试报告