Skip to content
Loki provides an easy way to handle locking scenarios on distributed systems.
Branch: develop
Clone or download
Pull request Compare This branch is 2 commits ahead, 15 commits behind Trendyol:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Loki.MSSQL
Loki.Tests
Loki
misc
.gitattributes
.gitignore
Loki.sln
README.md

README.md

Loki


alt tag

Loki provides an easy way to handle locking scenarios on distributed systems.

Features:

  • Support Redis locking handler for primary
  • Support MSSQL locking handler for secondary
  • Multiple locking handlers can be added such as MongoDB etc
  • Secondary locking handler can be set for against connection failure problems

Basic Loki Workflow:

alt tag

Usage:

Firstly you have to easily initialize the Loki with LokiConfigurationBuilder.

List<EndPoint> redisEndPoints = new List<EndPoint>
{
	new DnsEndPoint("redisUri", redisPort)
};

LokiConfigurationBuilder.Instance.SetServiceKey("SimpleTestClient")
						.SetPrimaryLockHandler(new RedisLokiLockHandler(redisEndPoints.ToArray()))
						.Build();

Then just use Locking.Instance.ExecuteWithinLock() method where you want to provide concurrency.

Locking.Instance.ExecuteWithinLock(() =>
{
	//do somethings..
},  expiryFromSeconds: 2);

Also you can easily implement custom locking handlers.

public class FooLockHandler : LokiLockHandler
{
    public override bool Lock(string serviceKey, int expiryFromSeconds)
    {
        //Lock operations
    }

    public override void Release(string serviceKey)
    {
        //Release operations
    }
}

If you want to use MSSQL locking handler for secondary, firstly you need to create LokiLockings table as below:

CREATE TABLE [dbo].[LokiLockings](
	[ServiceKey] [varchar](50) NOT NULL,
	[CreationDate] [datetime] NOT NULL,
 CONSTRAINT [PK_LokiLockings] PRIMARY KEY CLUSTERED 
(
	[ServiceKey] ASC
))

then just:

LokiConfigurationBuilder.Instance.SetServiceKey("SimpleTestClient")
						.SetPrimaryLockHandler(new RedisLokiLockHandler(redisEndPoints.ToArray()))
						.SetSecondaryLockHandler(new MSSQLLokiLockHandler("connectionString"))
						.Build();
You can’t perform that action at this time.