csredis icon indicating copy to clipboard operation
csredis copied to clipboard

多进程多线程使用RedisHelper.LPop取出相同项

Open lonelyislong opened this issue 3 years ago • 1 comments

new Thread(() =>
                {
                    LeaguerAccountDto account = null;

                    try
                    {
                        while (RedisHelper.LLen(key) > 0)
                        {
                            account = RedisHelper.LPop<LeaguerAccountDto>(key);
                            if (account != null)
                            {
                                  //业务处理
                            }
                        }
                    }
                  catch(Exception ex){
                  //记录错误
                  }
            });

希望依赖redis lpop命令的原子性来多个程序多线程跑数据,加快进度,数据表因为有做主键约束,结果发现有取到重复项现象: [2021-12-20 11:08:40] 记录已存在:Duplicate entry '25a814b3-5177-4f14-b486-9bf9849e1903-20211126' for key 'PRIMARY',跳过执行 [2021-12-20 11:09:03] 记录已存在:Duplicate entry '22aad058-9f14-46f2-a9ac-dae7b67d1b31-20211126' for key 'PRIMARY',跳过执行 现在的问题:难道redis lpop命令不是原子性?如果有大神看到,麻烦解答下,非常感谢!!!

lonelyislong avatar Dec 20 '21 03:12 lonelyislong

不是

2881099 avatar Jan 17 '22 23:01 2881099