The invention discloses a sales locking method and
system based on caching, and the method comprises the following steps: S1, dividing commodity information into a plurality of parts according to themodulus of a commodity code, and respectively storing the commodity information in a cache
library of a corresponding code of Redis according to a preset rule; S2, obtaining and analyzing a sales locking request of the commodity to obtain a request
list; S3, recording an inventory change intermediate table in the same transaction according to the request
list, and then updating the commodity information in the cache
library of the corresponding code of the Redis; and S4, asynchronously updating the commodity information in the
database by using the second-level JOB according to the inventory change intermediate table. According to the method, the use of a single Redis cache
library for storing a large amount of data is avoided; query efficiency is improved,
atomicity of LUA scripts is usedfor replacing
database affairs to guarantee
data consistency, inventory
concurrency control is conducted by means of the characteristics of Redis single threads, and the gray scale state is used forsolving the problem that cache and
database data are inconsistent due to
data processing when requests come in the process of switching the data to the cache.