static void Lock() { Console.WriteLine("Start.........."); RedisValue token = Environment.MachineName; var r1 = RedisHelper.LockTake("test", token, TimeSpan.FromSeconds(10)); //實際項目秒殺此處可換成商品ID if (r1) { try { Console.WriteLine("Working.........."); Thread.Sleep(5000); } finally { RedisHelper.LockRelease("test", token); } } Console.WriteLine("Over.........."); }