How to ensure data is hot data redis

There 2000w mySQL data, only the data stored in redis 20w, how to ensure that the data is hot data in redis?

 

1. Redis memory occupied by defining, based on its own data Redis out strategy, thermal loading data into memory.
So, calculate data about 20W occupied by the memory, and then set about Redis memory limit can be.

 

2. The question is what data?

Such as user data. There 2000w article database.
Active users:
within redis sortSet put two days (for the convenience of taking a day active users) logged users log in once ZADD once, set as it exists cover its fractions (login time). Key: login: users, value: Score timestamp, value userid. Set a cycle tasks such as deleting data 03:00:00 am every sort set the previous day before 3:00 (no guarantee set sprawl, leaving the last couple of days of active users).

When taken to get the current time stamp (int 10 bits) minus one day can be taken by the fraction range of active users over 24h.

 

3. Look for your question, we should just put Redis as cache to use.
To provide a simple realization of ideas cache invalidation: LRU (least recently used phase-out)
that is redis cache hit every time, give a certain increase in the cache hit ttl (expiration time) (as the case may be set, such as 10 minutes).
after some time, a large thermal ttl data will not expire automatically, substantially over the cold ttl data set immediately ineffective.

 

4.

redis memory size of the data set to rise to a certain amount of time, will perform data elimination strategy.

redis offers six data out of the policy:

redis memory size of the data set to rise to a certain size and they will perform data elimination strategy. redis-out policy data provides 6:
volatile-LRU: least recently used to pick out a data set from the data set the expiration time (server.db [i] .expires) in
volatile-ttl: expiration time has been set from the data set (server.db [i] .expires) were selected to be stale data out
volatile-random: arbitrarily selecting data from the set-out expiration time data set (server.db [i] .expires) in
allkeys-lru: data from set (server.db [i] .dict) were selected out of the least recently used data
allkeys-random: the data set (server.db [i] .dict) select any data out
no-enviction (expulsion): prohibits the expulsion data

 

 

Guess you like

Origin www.cnblogs.com/williamjie/p/11287210.html