public async Task LockExecuteTestAsync() { const string key = "lockTest"; var func = new Func <int, int, Task <int> >(async(a, b) => { // _testOutputHelper.WriteLine( // $"thread-{Thread.CurrentThread.ManagedThreadId.ToString()} get the lock."); await Task.Delay(1000); return(await Task.FromResult(a + b)); }); var rdm = new Random(); for (var i = 0; i < 3; i++) { new Thread(async() => { var success = _redis.LockExecute(key, Guid.NewGuid().ToString(), func, out var result, TimeSpan.MaxValue, 3000, rdm.Next(0, 10), 0); if (success) { var res = await(result as Task <int>); _testOutputHelper.WriteLine( $"result is {res}.\t{DateTime.Now.ToLongTimeString()}"); } else { _testOutputHelper.WriteLine( $"failed to get lock.\t{DateTime.Now.ToLongTimeString()}"); } }) { IsBackground = true }