Redis 中的范围查询 - Spring Data Redis [英] Range Querying in Redis - Spring Data Redis
问题描述
有没有办法使用 Spring Data Redis 在 Redis 中实现 Range 查询?
is there a way we can implement Range queries in Redis using Spring Data Redis?
例如:
如果我的 Pojo 类具有日期(它不是主键)并且我需要落在所需日期范围内的数据,是否可以使用 Spring Data Redis 构建相同的查询而不是单独查询每个日期?
If my Pojo class has Date(which is not a primary key) and i require data that falls under a desired period of date, Is it possible with Spring Data Redis to construct a query for the same rather than querying each date individually?
推荐答案
对于 Redis ZSets,您有 ZSetOperations
接口,其中包含多个范围命令(请参阅 https://docs.spring.io/spring-data/redis/docs/2.5.1/api/org/springframework/data/redis/connection/RedisZSetCommands.html),主要是:
For Redis ZSets you have ZSetOperations
interface that have several range commands (see see https://docs.spring.io/spring-data/redis/docs/2.5.1/api/org/springframework/data/redis/connection/RedisZSetCommands.html), the main one being:
range(K key, long start, long end)
另外,还有几个 rangeByXXX
.
有关 Redis ZSet 和范围操作的更多信息,请参阅 https://redis.io/commands/zrange
More info on Redis ZSets and range operations see https://redis.io/commands/zrange
如果您想要更强大的查询,我建议您查看 RediSearch (https://oss.redislabs.com/redisearch/).这里有 Spring 集成 https://oss.redislabs.com/redisearch/
If you want more powerful queries I recommend you take a look at RediSearch (https://oss.redislabs.com/redisearch/). There is Spring Integration here https://oss.redislabs.com/redisearch/
这篇关于Redis 中的范围查询 - Spring Data Redis的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!