PlayFab/consuldotnet

Aquire Lock custom KV value

Closed this issue · 0 comments

Hi,

This is a "feature request" and not an issue.

The package works great so far. I am trying to use this especially for leader election between services.
https://www.consul.io/docs/guides/leader-election.html

I can acquire and release the lock without any problems but as per recommendations on the consul.io page I would rather set the KV lock value to something more meaningful.

Another nice thing to have would be to receive the session ID back upon successfully acquiring the lock (I guess IDistributedLock can hold this information alongside the IsHeld flag).

I can then use this as a stamp to determine which service has processed my processing request from a pool of many.

Hope these make sense from a usability perspective.

Thanks!

Later edit:

I just realised you can actually do this with the other constructor which takes in LockOptions and then you can pass your own byte array in.

serviceLock = client.CreateLock(new LockOptions("test_service") { Value = payload });

Also if you want to retrieve the session ID you can do something likes this:

var serviceKV = await client.KV.Get("test_service");
var sessionID = serviceKV.Response.Session;

I will close the issue as it seems all the required functionality is there.