【问题标题】:How are sorted sets stored in redis when set using Spring + Jedis?使用 Spring + Jedis 设置时,排序集如何存储在 redis 中?
【发布时间】:2018-10-18 18:43:25
【问题描述】:

我有一个带有 spring-data-redis (1.8.7) 和 jedis (2.9.0) 的 Spring 4.3.9 应用程序。我可以使用以下代码轻松设置和检索 ZSET:

// Commented out -- but below line works fine too
// redisTemplate.opsForZSet().remove("score", userId);
Double scoreInRedis = redisTemplate.opsForZSet().score("score", userId);
redisTemplate.opsForZSet().add("score", userId, (double) score);

但是,当我转到 redis CLI 并尝试使用“score”键检索 ZSET 时,我没有得到任何返回。所以我尝试了以下命令:

ZCARD "score" <-- this should give number of items wi
(integer) 0
ZSCORE "score" userId <--> I use the actual number here for the userId
(nil)

ZREVRANGE 或 ZREVRANGEBYSCORE 等其他命令都返回 (nil)。

我知道我的密钥正在设置,因为“信息密钥空间”显示密钥之间的差异和过期时间正好为 1——这是我的分数 ZSET。如果我从 Spring 应用程序中删除 ZSET,则密钥和过期密钥的数量是相同的。所以我知道我的钥匙在某处。

老兄,我的 ZSET 呢??我如何通过 CLI 访问它?我可以轻松地继续开发而无需通过 CLI 访问,但我想了解我在哪里。

【问题讨论】:

    标签: spring redis jedis spring-data-redis


    【解决方案1】:

    事实证明,我使用 RedisTemplate&lt;String, Long&gt; 时使用不当。我切换到基于 StringRedisTemplate 的 bean 并且神奇地我的密钥现在在 CLI 上可见。

    我仍然不确定使用另一个 bean 时我的密钥藏在哪里。

    顺便说一句,我在处理这个问题时遵循了这里的一些指导:https://medium.com/@smoothed9/redis-sorted-sets-with-spring-boot-and-redistemplate-66931e2e1b86

    【讨论】:

      猜你喜欢
      • 2017-06-17
      • 1970-01-01
      • 2015-02-21
      • 1970-01-01
      • 2018-12-04
      • 2022-10-01
      • 2013-02-06
      • 2015-10-13
      • 2016-12-10
      相关资源
      最近更新 更多