The reason for using redis, the cache and cache penetrate avalanche
Why not use redis map?
map is a local cache, along with jvm closed and destroyed, when the multi-instance Each instance must keep a cache. The redis is distributed cache, just keep a cache under the multi-instance, and provide a persistent, even if the server goes down data is not lost.
Cache penetration
Do not have access to a large number of cached data, resulting in a large number of requests fell database, database crash.
Solution: all existing data is loaded into a bitmap or Bloom filter, the requested data outset, there is no filter out, you can also check whether the data presence or absence of a database, a cache are empty, so then visit the short term will not enter the database.
Cache avalanche
Cache same time a large area of failure, resulting in many requests fall crash the database on the database.
solution:
We must first set a reasonable expiration policy, the expiration time is usually set to a fixed time + random time.
Second, we must ensure high availability redis clusters, select the appropriate persistence strategy, the redis recovery reload the cache. Made with locally cached frame java cache, a request to take the java the cache, then check Redis, if no re-check the database. Current-limiting component of the database to ensure that the request falls within a reasonable range, so that we can ensure that a portion of the normal user, but also ensure that the database does not collapse. Filtered off restrictor assembly designed to return a default value or prompts.