我目前正在研究一个项目,该项目需要使用Redis作为其缓存数据的主要存储库,并使用来自spring-data-redis-example的引用
我还需要做一些事情,例如获取和排序从redis检索到的列表,以实现这种情况,我尝试过的操作如下:
PageRequest.of(1,10,Sort.Direction.ASC,“等级”)
和
findBySomeAndThingOrderByRankAsc
但以上方法似乎都无法解决我的问题,即能够对从Redis检索到的数据进行排序
这是我的redis配置
@Configuration
@EnableRedisRepositories(basePackages = "com.example.db.redis.repository")
public class RedisConfiguration {
@Bean
JedisConnectionFactory jedisConnectionFactory() {
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
redisStandaloneConfiguration.setHostName(Properties.getString("redis.hostname"));
redisStandaloneConfiguration.setPort(Integer.parseInt(Properties.getString("redis.port")));
return new JedisConnectionFactory(redisStandaloneConfiguration);
}
@Bean
public RedisTemplate<?, ?> redisTemplate() {
RedisTemplate<?, ?> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(jedisConnectionFactory());
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new GenericToStringSerializer<>(Object.class));
return redisTemplate;
}
@Bean
public StringRedisTemplate strRedisTemplate() {
StringRedisTemplate redisTemplate = new StringRedisTemplate();
redisTemplate.setConnectionFactory(jedisConnectionFactory());
return redisTemplate;
}
}
这是pojo
@RedisHash("somehash")
public class SortOnRedisExample implements Serializable {
private static final long serialVersionUID = -895893308381522209L;
@Id
private String id;
@Indexed
private String some;
@Indexed
private String thing;
@Indexed
private Integer rank;
public SortOnRedisExample() {}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Integer getRank() {
return rank;
}
public void setRank(Integer rank) {
this.rank = rank;
}
public String getSome() {
return some;
}
public void setSome(String some) {
this.some = some;
}
public String getThing() {
return thing;
}
public void setThing(String thing) {
this.thing = thing;
}
}
我的问题是,spring-data-redis
是否以jpa样式支持排序/排序?如果没有,那么还有什么选择呢?
任何指针将不胜感激,谢谢!