static void Main(string[] args) { var endPoint1 = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1001); var endPoints = new[] { endPoint1 }; var redlock = new RedisLockManager(endPoints); var aggregateRootLock = new RedisAggregateRootLock(redlock); var revisionStore = new RedisRevisionStore(endPoints); var options = new RedisAtomicActionOptions(); options.LockTtl = TimeSpan.FromSeconds(1); options.ShorTtl = TimeSpan.FromSeconds(1); var atomicAction = new RedisAggregateRootAtomicAction(aggregateRootLock, revisionStore, options); var id = new HeadquarterId("e0846069-2730-4d3c-bc80-470d6a521d99", "elders"); var result = atomicAction.Execute(id, 1, () => { }); Console.WriteLine(result.IsSuccessful); Console.WriteLine(result.Value); }
static void Main(string[] args) { var endpoint1 = new IPEndPoint(IPAddress.Parse("192.168.99.100"), 1001); var endpoint2 = new IPEndPoint(IPAddress.Parse("192.168.99.100"), 1002); var endpoint3 = new IPEndPoint(IPAddress.Parse("192.168.99.100"), 1003); var endpoints = new[] { endpoint1, endpoint2, endpoint3 }; var lockManager = new RedisLockManager(endpoints); var result = lockManager.Lock("resource_key", TimeSpan.FromSeconds(60)); if (result.LockAcquired) { try { // do stuff } finally { lockManager.Unlock(result.Mutex); } } }