Fixed a potential issue where locks could get out of sync between Redis instances.

This commit is contained in:
Jon Chambers
2020-06-07 12:55:39 -04:00
committed by Jon Chambers
parent 251364d8be
commit 1b5dc0e434

View File

@@ -56,7 +56,11 @@ public class LockingRateLimiter extends RateLimiter {
final String lockName = getLockName(key);
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;
}