Closed
Description
I use spring-integration-redis for distibution lock and I found that if the lock key is expired, it will throw an exception when I unlock the lock. here is my code:
RedisLockRegistry registry = new RedisLockRegistry(getConnectionFactory(), this.registryKey);
Lock lock = registry.obtain("foo");
lock.lock();
try {
//do something that may be expired
}
finally {
lock.unlock();//it throws an exception if the redis key is expired
}
}
I read the source code of 'unlock' method in RedisLockRegistry class I found that:
if (!this.isAcquiredInThisProcess()) {
throw new IllegalStateException("Lock was released in the store due to expiration. The integrity of data protected by this lock may have been compromised.");
}
It seems that it is not a bug. I think it mislead the developers likely, at least it mislead me. so, my question is that why not just ignore case that the redis key is expired. Isn't it more friendly to developers. And then I needn't to embeded a try catch block in finally block above.
My English is not good enough probably, Did I describe my question clearly?
Could you please explain that for me? thank you very much!