In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
@ Component
Public class RedisLock {
Logger logger= LoggerFactory.getLogger (RedisLock.class)
Private static final String LOCK_SUCCESS = "OK"
Private static final String SET_IF_NOT_EXIST = "NX"; / / NX is millisecond, EX is second
Private static final String SET_WITH_EXPIRE_TIME = "PX"
/ * attempt to acquire distributed lock * @ param lockKey lock * @ param requestId request ID * @ param expireTime timeout * @ return obtained successfully * / public boolean tryGetDistributedLock (String lockKey, String requestId, int expireTime) {Jedis jedis=null; try {jedis= Const.jedisPoolCommon.getResource (); String result = jedis.set (lockKey, requestId, SET_IF_NOT_EXIST, SET_WITH_EXPIRE_TIME, expireTime) If (LOCK_SUCCESS.equals (result)) {return true;}} catch (Exception ex) {logger.error ("tryGetDistributedLock exception" + ex);} finally {if (jedished exception null) {jedis.close ();}} return false;} private static final Long RELEASE_SUCCESS = 1L / * * release distributed lock * @ param lockKey lock * @ param requestId request identifies whether @ return has been successfully released * / public boolean releaseDistributedLock (String lockKey, String requestId) {Jedis jedis= null; try {jedis=Const.jedisPoolCommon.getResource (); String script = "if redis.call ('get', KEYS [1]) = ARGV [1] then return redis.call (' del', KEYS [1]) else return 0 end" Object result = jedis.eval (script, Collections.singletonList (lockKey), Collections.singletonList (requestId)); if (RELEASE_SUCCESS.equals (result)) {return true;}} catch (Exception ex) {logger.error ("releaseDistributedLock exception" + ex);} finally {if (jedised exception null) {jedis.close ();}} return false;}
}
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.