Skip to content
/ Loki Public
forked from Trendyol/Loki

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

Notifications You must be signed in to change notification settings

GokGokalp/Loki

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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();

About

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

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%