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

This commit is contained in:
Jon Chambers authored and Jon Chambers committed 2020-06-07 18:27:11 -04:00
1 parent 251364d8be
commit 1b5dc0e434
1 file changed
+5 -1
@@ -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;
}