当前位置:网站首页>[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


边栏推荐
- matlab实时作出串口输出数据的图像
- 自动化测试之数据驱动DDT
- LDP related knowledge
- 基于SEIR模型的网络医疗众筹传播建模与仿真分析
- Nest. JS uses express but not completely
- How to make your JS code more beautiful
- Shib (firewood Dog Coin) rose hundreds of times in January. What core elements does a hundred times coin need? 2021-05-09
- Understanding of "dbdnet: a deep boosting strategy for imagedenoising"
- Unified handling of global exceptions
- Niuke / Luogu - [noip2003 popularization group] stack
猜你喜欢

nodejs启动mqtt服务报错SchemaError: Expected `schema` to be an object or boolean问题解决

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

基于数据要素流通视角的数据溯源研究进展

12. Neural network model

牛血清白蛋白修饰牛红细胞超氧化物歧化酶SOD/叶酸偶联2-ME白蛋白纳米粒的制备

Backtracking - 77. combination

letfaw

Js理解之路:Object.call与Object.create()实现继承的原理

06_ UE4 advanced_ Set up a large map using the terrain tool

Representation and implementation of stack (C language)
随机推荐
如何让你的 JS 代码写得更漂亮
markdown写作平台
Packet switching and label switching in MPLS
【redis】③ 数据淘汰策略、pipeline 管道命令、发布订阅
URL address mapping configuration
Installation and configuration of VMware esxi7.0
数据流通交易场景下数据质量综合管理体系与技术框架研究
这一次,彻底弄懂 Promise 原理
mysql事务的引入
Solidity智能合约开发 — 3.2-solidity语法数组、结构体、映射
FreeRTOS personal notes - mutex
【目录】Nodejs、npm、yarn、BUG
bond网卡模式配置
【论文笔记】—目标姿态估计—EPro-PnP—2022-CVPR
Redirection and request forwarding
Binary tree -- 700. Search in binary search tree
MySQL - master-slave replication
融合聚类信息的技术主题图可视化方法研究
基于SEIR模型的网络医疗众筹传播建模与仿真分析
JVM 三色标记法与读写屏障