当前位置:网站首页>Interviewer: do you understand redis' shared object pool?
Interviewer: do you understand redis' shared object pool?
2022-06-12 01:12:00 【Hua Weiyun】
I'm waiting anxiously in the interview room , Suddenly I heard footsteps outside the door , The door is then opened , The young man with clean clothes and beautiful face came in , A faint fragrance of men's perfume comes to us. .
interviewer :“ Usually used in work Redis Do you ?”
I :“ It's used a lot .” I'm happy in my heart ,Redis I'm familiar with it , What are the five data types 、 The two persistence methods are back to back .
interviewer :“Redis Shared object pool, see ?”
“ This .. Not much in-depth understanding .” I hesitated , The palms of my hands are already sweating .
interviewer :“ Go back and wait for the news .”
This sentence is clear , And then there's no then . Failure is the mother of success , I'm not discouraged , Decided to mend it right away .
Shared object pool
Creating a large number of duplicate integer types is bound to consume a lot of memory , So in Redis Internally maintained a from 0 To 9999 Integer object pool for , This is it. Shared object pool .
To verify and understand , We use object refcount Command to check the number of object references , The effect is as follows :
127.0.0.1:6379> set one-more-num1 404OK127.0.0.1:6379> object refcount one-more-num1(integer) 2172.24.130.22:6379> set one-more-num2 404OK127.0.0.1:6379> object refcount one-more-num2(integer) 3Set up one-more-num1 by 404 after , Directly use integer objects in the shared pool , So the number of references is 2( Another reference is on the object pool ); To set up one-more-num2 by 404 after , The number of references becomes 3.
But here's the thing : When setting the maximum memory value (maxmemory) And enable LRU Relevant elimination strategies ( Such as :volatile-lru、allkeys-lru) when , Shared object pools will be disabled .
Why is there no string object pool ?
A key operation in the shared object pool is to determine whether objects are equal .
Redis There are only integer type object pools in the , Because the time complexity of integer comparison algorithm is O(1), Only kept 10000 An integer to prevent excessive waste of the object pool .
Relatively speaking , The time complexity of string comparison algorithm is O(n), In particular, the comparison of long strings is more performance consuming .
and , There is a high probability that integer types will be reused , The probability that a string will be reused is much lower than , So in Redis Only integer type objects are shared in the pool .
Interviewer, you'll see , You don't care about me today , Tomorrow I'll keep you up , Ha ha ha ...
reference :
《Redis Design and implementation 》
《Redis Development and operations 》
《Redis Deep Adventure : Core principles and application practice 》
边栏推荐
- Esp8266wifi development board collects temperature and humidity data and uploads them to the Internet of things platform
- What is the digital twin of Yixin Huachen and what is its application value?
- Jvm: thread context classloader
- Blue Bridge Cup - 2012b Group real question 3 specific drinking capacity
- How much is the child's critical illness insurance coverage appropriate? Which product is better now
- [工具] spacing.js 测间距
- System. Commandline option
- How can functional tests be quickly advanced in one month? It is not a problem to clarify these two steps
- [answer] business use cases and system use cases are mixed together
- Websocket server practice
猜你喜欢

Websocket server practice

Equipment encryption of industrial control security

Defect detection, introduction to Halcon case.

模块八-设计消息队列存储消息数据的 MySQL 表格

Low code platform design exploration, how to better empower developers

One article to show you how to understand the harmonyos application on the shelves

Go out with a stream

flowable 工作流

Online Fox game server - room configuration wizard - component attribute and basic configuration assignment

In depth description of Weibull distribution (2) meaning of parameters and formulas
随机推荐
Crawler case 05 - parsing websites using XPath
如何优化PlantUML流程图(时序图)
Data visualization big screen - big screen cloud minimalist user manual
Global and Chinese lutetium oxide powder industry investigation and analysis and Investment Strategy Research Report 2022-2028
Websocket server practice
Make good use of these 28 tools, and the development efficiency soars
Online Fox game server - room configuration wizard - component attribute and basic configuration assignment
模块八-设计消息队列存储消息数据的 MySQL 表格
Weibull Distribution韦布尔分布的深入详述(1)原理和公式
be based on. NETCORE development blog project starblog - (11) access statistics
【系统分析师之路】系统分析师历年真题大汇总
Analysis report on operation trends and development strategies of global and Chinese plastic adhesive industry 2022-2028
Lambda intermediate operation sorted
Devops landing practice drip and pit stepping records - (1)
About MySQL password modification failure
MATLAB basic application 02 wind stock data introduction and use case:
Lambda中间操作map
Article 5: Design of multi-functional intelligent trunk following control system | undergraduate graduation design - [learning of controller arduino+stm32]
Esp8266wifi development board collects temperature and humidity data and uploads them to the Internet of things platform
Go out with a stream