public static long unLock(CacheConfigBean cacheConfigBean, String key, Object valueObj) throws Exception {
        final LockData lockData = LOCK_THREAD_DATA.get();
        if (lockData == null)
            throw new IllegalMonitorStateException("You do not own the lock: " + key);

        long startNano = System.nanoTime();

        final int newLockCount = lockData.getLockCount().decrementAndGet();
        if (newLockCount > 0) {
            return 1;
        } else if (newLockCount < 0) {
            throw new IllegalMonitorStateException("Lock count has gone negative for lock: " + key);
        } else {
            try (Jedis jedis = Redis.useDataSource(cacheConfigBean).getResource()) {
                final String _value = ObjectCacheOperate.get(jedis, key);
                if (_value == null) {
                    LOG.warn(String.format("key: %s, -1 (没有对应的缓存)", key));
                    return -1;
                }
                final String value = FormatUtil.formatValue(valueObj);
                if (!_value.equals(value)) {
                    LOG.warn(String.format("key: %s, (_value: %s) != (value: %s), -2 (入参值 和 缓存值 不匹配)", key, (_value == null ? "null" : _value), (value == null ? "null" : value)));
                    return -2;
                }

                final long result = ObjectCacheOperate.del(jedis, key);

                if (!EnvUtil.getEnv().equals(EnvUtil.PRODUCTION)) {
                    long endNano = System.nanoTime();
                    LOG.info(String.format("key: %s, 分布式解锁, 累计耗时: %s 纳秒", key, (endNano - startNano) / 1000000));
                    LOG.info(String.format("DEL key: %s = result: %s", key, result));
                }

                return result;
            } catch (Exception e) {
                LOG.error(e);
                return -3;
            } finally {
                LOCK_THREAD_DATA.remove();
            }
        }
    }
public static long unLock ( CacheConfigBean cacheConfigBean , String key , Object valueObj ) throws Exception { final LockData lockData = LOCK_THREAD_DATA . get ( ) ; if ( lockData == null ) throw new IllegalMonitorStateException ( "You do not own the lock: " + key ) ; long startNano = System . nanoTime ( ) ; final int newLockCount = lockData . getLockCount ( ) . decrementAndGet ( ) ; if ( newLockCount > 0 ) { return 1 ; } else if ( newLockCount < 0 ) { throw new IllegalMonitorStateException ( "Lock count has gone negative for lock: " + key ) ; } else { try ( Jedis jedis = Redis . useDataSource ( cacheConfigBean ) . getResource ( ) ) { final String _value = ObjectCacheOperate . get ( jedis , key ) ; if ( _value == null ) { LOG . warn ( String . format ( "key: %s, -1 (没有对应的缓存)" , key ) ) ; return - 1 ; } final String value = FormatUtil . formatValue ( valueObj ) ; if ( ! _value . equals ( value ) ) { LOG . warn ( String . format ( "key: %s, (_value: %s) != (value: %s), -2 (入参值 和 缓存值 不匹配)" , key , ( _value == null ? "null" : _value ) , ( value == null ? "null" : value ) ) ) ; return - 2 ; } final long result = ObjectCacheOperate . del ( jedis , key ) ; if ( ! EnvUtil . getEnv ( ) . equals ( EnvUtil . PRODUCTION ) ) { long endNano = System . nanoTime ( ) ; LOG . info ( String . format ( "key: %s, 分布式解锁, 累计耗时: %s 纳秒" , key , ( endNano - startNano ) / 1000000 ) ) ; LOG . info ( String . format ( "DEL key: %s = result: %s" , key , result ) ) ; } return result ; } catch ( Exception e ) { LOG . error ( e ) ; return - 3 ; } finally { LOCK_THREAD_DATA . remove ( ) ; } } }
解锁

@param cacheConfigBean
@param key
@param valueObj
@return
@throws Exception