--------------- Redis five data types and application scenarios --------------------------- ------
String: General cache do some complicated counting function of the
List: do simple message queue functions
Hash: Single Sign
Set: Global functions to do heavy
SortedSet: do chart application, take TopN operation; delay task; do range seek
------------------------------------ redis distributed lock --------- redis distributed transaction ----------------------------------------
What distributed transactions:
Multiple services at the same time modify records, to ensure data consistency.
Distributed ideas:
- By setting a single lock redis, if there is key, it is believed there are other clients in use, waiting for the lock release.
- If the key is not present, indicating that no client is using, you can perform the task is finished, unlock, delete key.
-
Problems 1:
After acquiring the lock, service downtime, because the key is unique, it can not be deleted.
Problem 1 Solution
Set an expiration time.
Question 2 exists
Task execution is too long, more than the expiration time.
Problem 2 Solution
By a daemon thread to thread continued life.
3 problems:
Task execution caused by an infinite loop, creating an infinite continued life.
Question 3 Solution:
Sets the maximum time continued life.