当前位置:网站首页>[redis] ③ data elimination strategy, pipeline command, publish and subscribe
[redis] ③ data elimination strategy, pipeline command, publish and subscribe
2022-07-26 00:20:00 【Zhangguoqing (Qing Yi)】
Catalog
One 、 Data elimination strategy
Redis The biggest reason why it is fast is : It stores data in Memory In . The capacity of memory is incomparable with that of hard disk , The memory capacity will always reach the maximum . When the memory capacity reaches a certain value, you need to correct Redis Delete the data stored in memory ( Eliminate ) operation , Delete those data ? When to delete ?
stay Redis in , Allows the user to set the maximum memory size (Redis The maximum capacity of data that can be stored )【 stay Redis Configuration in the configuration file of 】
maxmemory 1G
maxmemory-policy noeviction # No elimination strategy , beyond 1G Report errors 
lft: according to key Use frequency To eliminate
lru: according to key Recent use of Time To eliminate
- volatile-lru: Set the timeout time in the data , Delete the least commonly used data
- allkeys-lru: all key Delete the least frequently used data in
- volatile-random: Delete randomly in the data with timeout set
- allkeys-random: be-all key Randomly delete
- volatile-ttl: Query all set timeout data , Then sort it immediately , Delete the data that is about to expire
- noeviction: Delete operation will not be performed , If the memory overflows, an error is reported
- volatile-lfu: Expel the least frequently used key from all keys configured with expiration time
- allkeys-lfu: Eject the least frequently used key from all keys
Two 、Java Basic use Redis(Jedis)
<dependencies>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
public class BasicTest {
private Jedis jedis;
@Before
public void init() {
jedis = new Jedis("192.168.80.130", 6379);
}
@Test
public void test1() {
jedis.flushAll();
System.out.println(jedis.dbSize());
}
@After
public void destroy() {
if (jedis != null)
jedis.close();
}
}
3、 ... and 、pipeline
- Put the command into the pipeline , Bulk send to Redis Server side , Improve performance , Greatly reduce network consumption
- There is no connection between commands executed in batches
- Not all data structures can be used pipeline command
- pipeline The operation of is not atomic

public class PipelineTest {
private Jedis jedis;
@Before
public void init() {
jedis = new Jedis("192.168.80.130", 6379);
}
@Test
public void testPipeline() {
Times.test(" Pipeline command is not used ", this::noPipeline);
Times.test(" Use the pipeline command ", this::pipeline);
}
private void noPipeline() {
for (int i = 0; i < 66666; i++) {
jedis.set("no" + i, String.valueOf(i));
}
}
private void pipeline() {
// Create pipes
Pipeline pipeline = jedis.pipelined();
for (int i = 0; i < 66666; i++) {
// Add commands to the pipeline
pipeline.set("pipeline" + i, String.valueOf(i));
}
// Synchronous execution of commands
pipeline.sync();
}
@After
public void destroy() {
if (jedis != null)
jedis.close();
}
}
Execution results :
Four 、 Publish subscribe


边栏推荐
- Recent impressions about bull market and defi 2021-05-17
- CyclicBarrier
- bond网卡模式配置
- Backtracking - 17. Letter combinations of phone numbers
- Markdown writing platform
- Representation and implementation of stack (C language)
- Binary tree - 110. Balanced binary tree
- 07_ UE4 advanced_ MP value of firing fireball and mechanism of attacking blood deduction
- Binary tree -- 257. All paths of binary tree
- 二进制表示--2的幂
猜你喜欢

Nest. JS uses express but not completely

用了MQ消息中间件后,我开始后悔了...

【Redis】② Redis通用命令;Redis 为什么这么快?;Redis 的数据类型

【论文笔记】—目标姿态估计—EPro-PnP—2022-CVPR

Bond network card mode configuration

CyclicBarrier

基于SEIR模型的网络医疗众筹传播建模与仿真分析

Binary tree - 530. Minimum absolute difference of binary search tree

Recent impressions about bull market and defi 2021-05-17

Redis夺命十二问,你能扛到第几问?
随机推荐
Unity—欧拉角,四元数
JVM 三色标记法与读写屏障
Use of redis
Revision of Journal of Computational Physics
MySQL - master-slave replication
appium 从启动到测试再到结束流程梳理
Binary tree - 654. Maximum binary tree
Backtracking - 17. Letter combinations of phone numbers
【redis】③ 数据淘汰策略、pipeline 管道命令、发布订阅
Binary tree - 226. Flip binary tree
一个List到底能存多大的数据呢?
Unity -- Euler angle, quaternion
Sliding window_
Niuke / Luogu - [noip2003 popularization group] stack
软件测试同行评审到底是什么?
分布式事务 :可靠消息最终一致性方案
MySQL——主从复制
What is software testing peer review?
After using MQ message oriented middleware, I began to regret
自动化测试之数据驱动DDT