Skip to content

affinity/redlock-cs-async

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

redlock-cs

Build status

Distributed lock with Redis and C# (based on the redlock algorithm)

Redlock-cs is available through nuget as redlock-cs-async package.

Usage

Check our Unit Test.

The API is based on antirez Ruby implementation and works as in the following example:

// Declare a Distributed Lock based on 3 REDIS servers

var dlm = new Redlock(
		ConnectionMultiplexer.Connect("127.0.0.1:6379"), 
		ConnectionMultiplexer.Connect("127.0.0.1:6380"), 
		ConnectionMultiplexer.Connect("127.0.0.1:6381")
	      );

// Declare lock object.
Lock lockObject;

// Try to acquire the lock (with resourceName as lock identifier and an 
// expiration time of 10 seconds).
var locked = dlm.Lock(
		resourceName,
		new TimeSpan(0, 0, 10), 
		out lockObject
	     );

// If locked is true, lockObject is populated and the lock has been acquired, 
// otherwise the lock has not been acquired.

// Tries to release the lock contained in lockObject.
dlm.Unlock(lockObject);

TODO

  • Disposable pattern.
  • Hide StackExchange.Redis library inside Redlock object.

About

Asynchronous Distributed lock with Redis and C# (based on http://redis.io/topics/distlock)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages