redis data consistency

Turn:  https://blog.51cto.com/538858/2328219

 

Mode 2:
database and redis are dealing with different intensities to be consistent real-time data type database processing requirements, such as financial data, transaction data processing Redis does not require the same strong real-time data, such as the hottest website posted rankings

redis and MySQL data synchronization code level generally can do: Read: Read redis-> No, read mysql-> mysql to write data back to redis Write: Write mysql-> success, write redis

Concurrency is not high: Reading: Read redis-> No, read mysql-> mysql to write data back to redis, any redis taken directly from the; Write: Write mysql-> success, write redis;

High concurrency: Read: Read redis-> No, read mysql-> mysql to write data back to redis, taken directly from any redis in; write: asynchronous, then, to write redis cache, direct return; regularly or specific actions to save data to mysql, can do multiple updates, once saved;

- Note: If you want to use to write redis redis transaction:
127.0.0.1:6379> WATCH the above mentioned id
the OK
127.0.0.1:6379> the MULTI
the OK
127.0.0.1:6379> INCR the above mentioned id
QUEUED
127.0.0.1:6379> EXEC
1) (Integer ) 342 183
127.0.0.1:6379>

Option 3:
Use lua script: redis using lua allow only the use of a script execution, in line with atomic transactions, but a lua script execution time can not be too large, otherwise it will clog

EVAL
EVAL command Lua script to perform the evaluation.

Syntax: EVAL script numkeys key [key ...] arg [arg ...]

script lua script content to note that the script should not be a Lua function.
numkeys represents the number of parameters specified key.
key [key ...] represents a list of key values corresponding to the script in the script may be used KEYS [1] KEYS [2] KEYS [3] KEYS [n] n from the beginning.
arg [arg ...] of naming parameters passed in line in the script list may be used ARGV [1] ARGV [2] ARGV [3] ARGV [n] n from the beginning.

One example is worth a thousand words explanation

eval "return {KEYS [1] , KEYS [2], ARGV [1], ARGV [2]}" 2 id name 3 mytest
implementation of the above script returns

1) "id"
2) "name"

3) "2"

4) "mytest"

 

Guess you like

Origin blog.csdn.net/softuse/article/details/90698238