当前位置:网站首页>Redis learning notes-2. Use of the client
Redis learning notes-2. Use of the client
2022-07-26 19:02:00 【I was born to be talented~~】
List of articles
1. Jedis
1.1 know Jedis

** Use java operation redis One of the middleware ,Redis Officially recommended java Connect development tools **
Jedis yes Redis An official product for Java The client of , Many interfaces are provided for Java Language call .
Use jedis object , Operation methods and functions redis Of api Exactly the same
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>4.1.1</version>
</dependency>
public class TestPing {
public static void main(String[] args) {
// 1、 new Jedis Object can
Jedis jedis = new Jedis("127.0.0.1", 6379);
// jedis All the commands are all the instructions we learned before ! So the instruction learning before is very important
String response = jedis.ping();
System.out.println(response); // PONG
}
}
1.2 Connect Jedis

- Each time is equivalent to one TCP Connect , Threads are not safe

1.3 Easy to use



1.4 Jedis Connection pool use
Comparison with direct connection


- Don't do it every time TCP Three handshakes connected , Four waves

Easy to use


Connection pool configuration
1. Resource number control

(1) compatible maxTotal



(2) compatible maxIdle and minIdle

- Actually maxTotal The maximum number of connections represented by the , It just gives an upper limit on the number of connections ,
- and maxIdle The maximum number of idle connections represented by the , Is really the maximum number of connections available for the business .
- If maxTotal and maxIdle The two are not equal , It will involve the destruction and creation of connections , There will be some overhead , Therefore, it is recommended to set maxIdle=maxTotal, Try to avoid the performance degradation of the connection pool caused by frequent connection creation and destruction , Enable connection pooling to achieve optimal performance .

2. Borrow and return parameters

3. common problem
(1) Timeout connection

maxWaitMillisSetting parameters
(2) Run out of resources

maxIdle and minIdleSet unequal conditions
4. Solutions


5. FAQ case demonstration
- Connection leakage - Connection not closed




2. lettuce
stay SpringBoot2.x after , Originally used jedis Was replaced by lettuce?
jedis : Using direct connection , If multiple threads operate , It's not safe ,
- If you want to avoid unsafe , Use jedis pool Connection pool ! More like BIO( Blocking ) Pattern
lettuce : use netty, Instances can be shared among multiple threads , There is no thread unsafe situation !
- Can reduce thread data , More like NIO Pattern

3. redis -py(Pathon client )
3.1 obtain redis-py

3.2 Basic use




4. go Language client
4.1 Redigo Client selection

3.2 Connect

3.3 Basic use

边栏推荐
- 一文详解MES系统给企业带来的5大好处,附应用场景
- NFT数字藏品系统开发:“中国旅游日”山西首次发布古建筑数字藏品
- NFT数字藏品开发:数字藏品助力企业发展
- 实用工具网站推荐
- How to design test cases well
- js map使用
- likeshop外卖点餐系统开源啦100%开源无加密
- Brian behrendorf, general manager of openssf Foundation: it is estimated that there will be 420million open sources in 2026
- JS刷题计划——数组
- SSM integration - functional module and interface testing
猜你喜欢

Interview summary of some large factories

2022G1工业锅炉司炉上岗证题库及模拟考试

The class jointly built by famous oarsmen is new, and Professor qiuxipeng of Fudan University broadcast it live on Tuesday!

MySQL - 函数及约束命令

Neural network learning (2) introduction 2

SD NAND与eMMC优劣势对比

JS刷题计划——链表

Pyqt5 rapid development and practice 3.5 menu bar and toolbar

Comparison of advantages and disadvantages between SD NAND and EMMC

我酷故我在
随机推荐
js map使用
MySQL练习题初级45题(统一表)
Ministry of Finance: IC design enterprises and software enterprises will be exempted from corporate income tax this year and next!
Arm China responded to the "disconnection of Huawei supply" incident! Ren Zhengfei said "no impact"!
Automated test tool playwright (quick start)
2022 welder (elementary) operation certificate examination question bank and simulation examination
Lombok常用注解
rancher部署kubernetes集群
场景之分页查询设计
JS question brushing plan - array
图解用户登录验证流程,写得太好了!
The first ABAP ALV reporter construction process
SSM整合-异常处理器和项目异常处理方案
【在 Kotlin 中添加条件行为】
Huawei cloud · cloud sharing experts~
Operations research 69 | explanation of classic examples of dynamic planning
Sudden! Arm stops cooperating with Huawei! How big is the impact on Huawei?
Comparison of advantages and disadvantages between SD NAND and EMMC
JS map usage
议程速递 | 7月27日分论坛议程一览