Call redis packaged JedisUtils lock interface library

1, before performing the method of operation of the database define a key value, and add an identification of each key is able to distinguish

2, is first determined if the key value is defined exists, return to the direct method, if not present, the key value in jedisutil put in (that is, where data locking piece success), while remember release lock, The method of using jedisUtil.expire timed release lock.

3, after the operation step 2 is not successful return is already locked, then you can perform database operations. But after After calling the database and successfully obtained the values ​​returned by the database, remember to manually release the lock, otherwise it will automatically released by the figure after five minutes. Use jedisUtil.del method releases the lock.

After the above three steps can be completed after a lock on the database - a database CRUD difference - unlocking operation of the database, using the tools of the role jedisUtil be avoided because the card, duplicate clicks, and other misuse or illegal operations caused by multiple calls to the database the case, to avoid duplication of data problems in the database.

And summarize the important points:

A, must use a different identifier corresponding to a different key, a key operation can not be used with all the data

Second, some management systems may have more return, remember to release the lock operations are carried out in front of all of the return

Third, this method only applies to redis database

 

Guess you like

Origin www.cnblogs.com/LMCGD/p/11307914.html