SkillAgentSearch skills...

Loki

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

Install / Use

/learn @Trendyol/Loki
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

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

NuGet Packages

Install-Package LokiNet 

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();
View on GitHub
GitHub Stars35
CategoryDevelopment
Updated2y ago
Forks15

Languages

C#

Security Score

60/100

Audited on Aug 7, 2023

No findings