Fixed a potential issue where locks could get out of sync between Redis instances.
This commit is contained in:
parent
251364d8be
commit
1b5dc0e434
|
@ -56,7 +56,11 @@ public class LockingRateLimiter extends RateLimiter {
|
||||||
final String lockName = getLockName(key);
|
final String lockName = getLockName(key);
|
||||||
|
|
||||||
final boolean acquiredLock = jedis.set(lockName, "L", "NX", "EX", 10) != null;
|
final boolean acquiredLock = jedis.set(lockName, "L", "NX", "EX", 10) != null;
|
||||||
cacheCluster.useWriteCluster(connection -> connection.async().set(lockName, "L", SetArgs.Builder.nx().ex(10)));
|
|
||||||
|
if (acquiredLock) {
|
||||||
|
// TODO Restore the NX flag when the cluster becomes the primary source of truth
|
||||||
|
cacheCluster.useWriteCluster(connection -> connection.async().set(lockName, "L", SetArgs.Builder.ex(10)));
|
||||||
|
}
|
||||||
|
|
||||||
return acquiredLock;
|
return acquiredLock;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue