我目前正在开发一个项目,该项目需要 redis 作为缓存数据的主要存储库,使用来自spring-data-redis-example 的引用
我还需要执行诸如获取和排序从 redis 检索到的列表之类的操作,以实现这种情况,我尝试过的操作如下:
PageRequest.of(1, 10, Sort.Direction.ASC, "rank")
和
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 风格是否支持排序/排序?如果没有,有什么替代方法可以这样做?
任何指针将不胜感激,谢谢!