当前位置:网站首页>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
边栏推荐
- [hard core dry goods] which company is better in data analysis? Choose pandas or SQL
- How to apply smart contracts more wisely in 2022?
- No matter how busy you are, you can't forget safety
- 【无标题】
- Summer Challenge database Xueba notes, quick review of exams / interviews~
- Successful entry into Baidu, 35K monthly salary, 2022 Android development interview answer
- aggregate
- What does software testing do? What are the requirements for learning?
- 【C语言】字符串函数及模拟实现strlen&&strcpy&&strcat&&strcmp
- Mariadb root用户及普通用户的密码 重置
猜你喜欢
Mariadb root用户及普通用户的密码 重置
关于 Notion-Like 工具的反思和畅想
Common - Hero Minesweeper
Apprentissage du projet MMO I: préchauffage
Postman核心功能解析-参数化和测试报告
Notion 类生产力工具如何选择?Notion 、FlowUs 、Wolai 对比评测
使用 RepositoryProvider简化父子组件的传值
The problem of returning the longtext field in MySQL and its solution
Fuzor 2020软件安装包下载及安装教程
Django使用mysqlclient服务连接并写入数据库的操作过程
随机推荐
third-party dynamic library (libcudnn.so) that Paddle depends on is not configured correctl
大厂面试必备技能,2022Android不死我不倒
HAC集群修改管理员用户密码
信息/数据
HiEngine:可媲美本地的云原生内存数据库引擎
40000 word Wenshuo operator new & operator delete
acm入门day1
Hiengine: comparable to the local cloud native memory database engine
JAD的安装、配置及集成IDEA
vagrant2.2.6支持virtualbox6.1版本
How MySQL queries and modifies JSON data
使用easyexcel模板导出的两个坑(Map空数据列错乱和不支持嵌套对象)
Fundamentals of machine learning (III) -- KNN / naive Bayes / cross validation / grid search
爬虫练习题(二)
完爆面试官,一线互联网企业高级Android工程师面试题大全
Webuploader file upload drag upload progress monitoring type control upload result monitoring control
测试的核心价值到底是什么?
Zhongang Mining: analysis of the current market supply situation of the global fluorite industry in 2022
多分支结构
What are general items