【问题标题】:How to update a zset score with "where clause" in redis如何在redis中使用“where子句”更新zset分数
【发布时间】:2014-01-27 03:24:53
【问题描述】:

在 MySQL 中:

update zset.1 set score = score + 10 where value = 1 and score > 100

这意味着它不会更新,除非分数是 gt 100

在 Redis 和程序代码中:

score = zscore zset.1 1
if (score > 100) {
  score = zincrby zset.1 10 1
}

这应该可以,但它不是原子的。并发更新时分数会多次更新

另外,“WATCH”不适合我的情况,因为它的 RETRY 机制将是一个性能问题。

【问题讨论】:

    标签: sql database redis


    【解决方案1】:

    有两种方法:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-21
      相关资源
      最近更新 更多