当前位置:网站首页>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
边栏推荐
- 手机股票开户安全吗?靠不靠谱啊?
- redis集群模拟消息队列
- 打新债在哪里操作开户是更安全可靠的呢
- MMO project learning 1: preheating
- The problem of returning the longtext field in MySQL and its solution
- [OBS] qstring's UTF-8 Chinese conversion to blog printing UTF-8 char*
- 使用 RepositoryProvider简化父子组件的传值
- Get wechat avatar and nickname with uniapp
- 手机开户选择哪家券商公司比较好哪家平台更安全
- What is the core value of testing?
猜你喜欢
How MySQL queries and modifies JSON data
PHP uses ueditor to upload pictures and add watermarks
成功入职百度月薪35K,2022Android开发面试解答
UWB超宽带定位技术,实时厘米级高精度定位应用,超宽带传输技术
JAD的安装、配置及集成IDEA
Millimeter wave radar human body sensor, intelligent perception of static presence, human presence detection application
软件测试工程师是做什么的?待遇前景怎么样?
Android面试,android音视频开发
Android interview, Android audio and video development
MMO項目學習一:預熱
随机推荐
[FAQ] summary of common causes and solutions of Huawei account service error 907135701
Do you know several assertion methods commonly used by JMeter?
How to realize the Online timer and offline timer in the game
Bitcoinwin (BCW)受邀参加Hanoi Traders Fair 2022
Hiengine: comparable to the local cloud native memory database engine
Worthy of being a boss, byte Daniel spent eight months on another masterpiece
Android interview, Android audio and video development
MySQL中字段类型为longtext的值导出后显示二进制串方式
C#应用程序界面开发基础——窗体控制(5)——分组类控件
Two pits exported using easyexcel template (map empty data columns are disordered and nested objects are not supported)
Fuzor 2020軟件安裝包下載及安裝教程
How to choose the notion productivity tools? Comparison and evaluation of notion, flowus and WOLAI
城链科技数字化创新战略峰会圆满召开
Password reset of MariaDB root user and ordinary user
Is it safe for Guohai Securities to open an account online?
常用运算符与运算符优先级
Decision tree and random forest
The city chain technology Digital Innovation Strategy Summit was successfully held
How to apply smart contracts more wisely in 2022?
Successful entry into Baidu, 35K monthly salary, 2022 Android development interview answer