Redis 范围 : ERR Invalid stream ID specified as stream command argument

标签 redis

我正在尝试使用 XRANGE 迭代 Redis 流。 Redis documentation指出我需要在最后一个时间戳前加上 ( 前缀以使其具有独占性。引用文档:

In order to continue the iteration with the next two items, I have to pick the last ID returned, that is 1519073279157-0 and add the prefix ( to it. The resulting exclusive range interval, that is (1519073279157-0 in this case, can now be used as the new start argument for the next XRANGE call:

但是如果我这样做,就会收到错误,下面是两个命令,一个没有独占前缀,另一个会生成错误:

redis:6379> XRANGE unittest 1612384862718-0 +
1) 1) "1612384862718-0"
   2) 1) "x"
      2) "42"
2) 1) "1612384862780-0"
   2) 1) "x"
      2) "43"
3) 1) "1612384862888-0"
   2) 1) "x"
      2) "44"
redis:6379> XRANGE unittest (1612384862718-0 +
(error) ERR Invalid stream ID specified as stream command argument

Redis 文档中的示例对我来说看起来是一样的:

> XRANGE mystream (1519073279157-0 + COUNT 2
1) 1) 1519073280281-0
   2) 1) "foo"
      2) "value_3"
2) 1) 1519073281432-0
   2) 1) "foo"
      2) "value_4"

redis_version:6.0.6

最佳答案

Redis 6.2 中已经/将添加对独占/开放范围查询间隔的支持 - 请参阅 https://github.com/redis/redis/pull/8072 .

对于以前的版本,建议的方法是让客户端代码:

  1. 调用第一个XRANGE/XREVRANGE后,取最后一个ID
  2. 解析时间戳和序列的最后一个 ID(均为 64 位整数)
  3. 如果执行 XRANGE,请尝试增加序列。对于 XREVRANGE,将其递减。
  4. 如果序列上溢/下溢,则对时间戳执行相同的算术并初始化序列(XREVRANGE 为 MAXINT,XRANGE 为 0)
  5. 处理“0-0”和“MAXINT-MAXJNT”情况
  6. 在下次调用查询时使用新 ID 并重复

关于Redis 范围 : ERR Invalid stream ID specified as stream command argument,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66035607/

相关文章:

mysql - Redis 的 Comment&Like 设计

java - 如何在spring-boot-starter-data-redis中获取Jedis实例?

redis - 将可变数量的参数传递给 Redis Lua 脚本

database - Redis AOF 和 Tarantool WAL 日志的区别

c# - EF Core 2.0.0 和 Redis.Core 1.0.3 不能一起工作

ruby redis 客户端扫描与 key

flask - Flask Rate Limiter 是否适用于 Elasticache (Redis 2.8)?

ruby-on-rails - Rails Sidekiq 错误 : can't find object

python - RQ - 清空和删除队列

Django + Celery 长期定时任务