2881099 / csredis

.NET Core or .NET Framework 4.0+ client for Redis and Redis Sentinel (2.8) and Cluster. Includes both synchronous and asynchronous clients.
MIT License
2.01k stars 414 forks source link

为什么没有异步锁?在异步代码中使用RedisHelper.Lock导致线程线程饥饿该怎么处理 #471

Open haoxiaoname opened 1 year ago

haoxiaoname commented 1 year ago

高并发情况下

2881099 commented 1 year ago

高并发和并发锁,本来就是冲突的。

haoxiaoname commented 1 year ago

有好的建议吗,现在是进两条数据 想通过锁的方式来控制成1条,,,

2881099 commented 1 year ago

数据库插入吗?如果是关系数据库,直接设置一个 unique key 让第二次重复插入报错。

haoxiaoname commented 1 year ago

不是 数据库太弱了,我们是先写到redis 然后进队列 目前问题在redis 进两次会把第一次生成的id给替换掉,导致的数据不准确

2881099 commented 1 year ago

用 hincrBy 这个命令控制一下,当值是1才做操作

haoxiaoname commented 1 year ago

public async Task xxx(){ RedisHelper.Lock(xxx) // 这样会阻塞主进程吧? 能不能把RedisHelper.Lock 通过 async await 封装一份呢 }