I have a Spring 4.3.9 app w/ spring-data-redis (1.8.7) and jedis (2.9.0). I can easily set and retrieve a ZSET using the code as below:
// 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);
However, when I go to the redis CLI and try to retrieve the ZSET using the "score" key, I get nothing returned. So I've tried the following commands:
ZCARD "score" <-- this should give number of items wi
(integer) 0
ZSCORE "score" userId <--> I use the actual number here for the userId
(nil)
Other commands like ZREVRANGE or ZREVRANGEBYSCORE all return (nil).
I know that my key is being set because "info keyspace" shows a difference between keys and expires of exactly 1 -- which is my score ZSET. If I delete my ZSET from my Spring app, the number of keys and expiring keys is the same. So I know that my key is there somewhere.
Dude, where's my ZSET?? And how can I access it via the CLI? I can easily keep developing w/o accessing via the CLI but I'd like to understand where I'm off.
It turns out I was incorrectly using RedisTemplate<String, Long>
. I switched to a StringRedisTemplate
based bean & magically my key is now visible on the CLI.
I'm still not sure where my key was hiding when using the other bean.
Incidentally, I was following some of the guidance here when working on this: https://medium.com/@smoothed9/redis-sorted-sets-with-spring-boot-and-redistemplate-66931e2e1b86