Skip to content

Instantly share code, notes, and snippets.

@bennadel
Last active November 9, 2015 11:08
CFRedlock - My ColdFusion Implementation Of The Redlock Distributed Locking Algorithm From Redis
<cfscript>
// Create a Jedis-powered client - requires an array of JedisPool instances.
var locking = new lib.CFRedlock().createJedisClient(
jedisPools,
retryDelayInMilliseconds,
maxRetryCount
);
// Create an ISOLATED ColdFusion client (uses CFLock internally).
var locking = new lib.CFRedlock().createIsolatedClient(
retryDelayInMilliseconds,
maxRetryCount
);
// Create a test client with static GET / DELETE behavior.
var locking = new lib.CFRedlock().createTestClient(
[
[ true, true ],
[ false, false ],
[ true, true ]
],
retryDelayInMilliseconds,
maxRetryCount
);
</cfscript>
<cfscript>
// Create the locking client. The keyServers must adhere to the key server API.
// But, other than that, they can be implemented any way you want.
var locking = new lib.client.DistributedLockClient(
keyServers,
retryDelayInMilliseconds,
maxRetryCount
);
</cfscript>
<cfscript>
var myLock = locking.getLock( "my-lock-name", expirationInMilliseconds );
try {
someSynchronizedAction();
// No matter what, release the lock when you are done with it.
} finally {
myLock.releaseLock();
}
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment