Last active
November 9, 2015 11:08
CFRedlock - My ColdFusion Implementation Of The Redlock Distributed Locking Algorithm From Redis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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