当前位置:网站首页>Common interview questions of redis factory

Common interview questions of redis factory

2022-07-05 22:01:00 The sea of waves

Redis Common interview questions in large factories

Redis Application scenarios of

  • buffer
  • Ranking List
  • Counter
  • Distributed session
  • Distributed lock
  • Social networks
  • Latest list
  • The messaging system

See in detail Redis Of 8 Big application scenarios

Redis Consistency between buffer and database

Some time , Multiple system instances update a key. Can be based on Zookeeper Implement distributed locks . Each system passes Zookeeper Acquire distributed lock , Ensure the same time , Only one system instance can operate on one Key, No one else is allowed to read or write .

Data you want to write to the cache , from MySQL It was found in the , You have to write MySQL in , write in MySQL A time stamp must be saved in , from MySQL When we find out , Time stamps are also found .

Every time before you write , Let's first judge the current one Value Is the timestamp of the Value The time stamp of should be new . If so , Then you can write , otherwise , You can't overwrite new data with old data .
See in detail Redis, Double write consistency 、 Concurrent competition 、 Threading model

Redis Distributed lock and its principle

It is realized by the following four commands :

  • setnx
  • getset
  • expire
  • del

See in detail redis Principle and implementation of distributed lock

Redis Solve client session Share Information ?

in consideration of session Medium data similar map Structure , use redis in hash Storage session The data is appropriate , If you use a single value Storage session data , Without a lock , There will be session The problem of coverage , Therefore use hash Storage session, Save only this change at a time session Attribute data , Lock handling is avoided , Better performance .

If I change each one session Property to trigger the store , There is a lot of change session Property will be triggered multiple times redis Write operations , There is also an impact on performance , We are at the end of each request , Do it once session Writing , And it writes the changed property .

If you didn't do it this time session Change of , I can't do it redis Written in , Only if there is no change session Exceeding a time threshold ( Constant change session Refreshes the threshold for the expiration time ), It will trigger session preservation , In order to session Can extend the validity period .

See in detail In a few minutes redis Storage session share —— Design implementation

Redis What problems do distributed locks solve ?

1.1 Locks need to be unique

​ 1.2 The lock needs to have a timeout , Prevent deadlock

​ 1.3 Lock creation and lock timeout setting need to be atomic

​ 1.4 Lock timeout problem

​ 1.5 Reentrant problem of lock

​ 1.6 The problem of distributed locks under clusters

See in detail Redis Problems and solutions faced by distributed locks

Redis Why can distributed locks be supported ? How to use it ?

Redis Single process single thread mode , Using queue mode to change concurrent access into serial access , And multi client pairs Redis There's no competition for the connection .

See in detail Why? redis Can do distributed lock

Redis Of Buffer avalanche , Buffer penetration , Buffer breakdown , And Solutions

image-20210314160334027

image-20210314121724599

image-20210314121748142

See in detail Cache avalanche 、 breakdown 、 through ( With answers )

Redis Persistence mechanism of , Elimination strategy

Redis Master slave copy

Redis Sentinel mechanism

The three questions above , See in detail Redis, sentry 、 Persistence 、 Master-slave 、 Tear your hands LRU, I've got it all sorted out

Zset Underlying data structure , as well as ziplist and skiplist

zset The underlying storage structure includes ziplist or skiplist, Use when both of the following conditions are met ziplist, Other times skiplist, The two conditions are as follows :

  • The ordered set holds less elements than 128 individual
  • The length of all elements saved in an ordered set is less than 64 byte

When ziplist As zset The underlying storage structure of , Each collection element uses two packed list nodes next to each other to hold , The first node holds the members of the element , The second element holds the score of the element .

When skiplist As zset The underlying storage structure , Use skiplist Save elements and scores in order , Use dict To save the mapping relationship between elements and scores .

See in detail redis zset Underlying data structure

原网站

版权声明
本文为[The sea of waves]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140504117465.html