In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 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.
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.