标签:img stat aop data 分享 死锁 bsp nal thread
Redis有三个最基本属性来保证分布式锁的有效实现:
使用StackExchange.Redis 实现起来简单得很
static void Lock() { Console.WriteLine("Start.........."); var db = _redis.GetDatabase(); RedisValue token = Environment.MachineName; //实际项目秒杀此处可换成商品ID if (db.LockTake("test", token, TimeSpan.FromSeconds(10))) { try { Console.WriteLine("Working.........."); Thread.Sleep(5000); } finally { db.LockRelease("test", token); } } Console.WriteLine("Over.........."); }
最后附上GitHub地址:https://github.com/xiaopotian1990/RedisDemo
标签:img stat aop data 分享 死锁 bsp nal thread
原文地址:http://www.cnblogs.com/xiaopotian/p/6891019.html