In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the methods to ensure atomicity in redis. It is very detailed and has a certain reference value. Interested friends must read it!
Atomicity:
Atomicity is a characteristic in the transaction of a database. In the context of database transactions, atomicity means that all operations in a transaction (transaction) are either completed or not completed, and do not end in the middle.
For Redis, the atomicity of a command means that an operation can no longer be divided, and the operation is either executed or not executed.
Reasons for the atomicity of Redis operations:
The operation of Redis is atomic because Redis is single-threaded.
Redis's performance in concurrency:
Redis's API is atomic, so are so many commands atomic in concurrency?
There is the following code:
$redis= newRedis (); $redis- > connect ('127.0.0.1); for ($I = 0 * * val'); $num++;$redis- > set (' val',$num); usleep (10000);}
Execute the above program with two terminals and find that the result of val is less than 2000, then you can know that executing multiple Redis commands in the program is not atomic, which is the same as the performance of an ordinary database.
If you want to achieve atomicity in the above program, you can change get and set to a single command operation, such as incr, or use Redis transactions, or use Redis+Lua.
For Redis, executing API such as get, set and eval is a task, these tasks will be carried out by the thread of Redis, and the task either succeeds or fails, which is why the command of Redis is atomic.
All the API provided by Redis itself are atomic operations, and the transactions in Redis are actually to ensure the atomicity of batch operations.
The above is all the contents of the methods to ensure atomicity in redis. Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.