2 years ago
#54012
JuGi
How to get hash value using key on spring data redis?
On redis I have added key S000, and I want load hash object with that key.
I always get NULL from even I passed the correct key.
How can I do that, please find screenshot below for more detail.
Thank!
@Configuration
@EnableRedisRepositories
public class RedisConfig {
@Bean
public JedisConnectionFactory connectionFactory() {
RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration();
configuration.setHostName("localhost");
configuration.setPort(9000);
return new JedisConnectionFactory(configuration);
}
@Bean
public RedisTemplate<String, User> redisTemplate() {
RedisTemplate<String, User> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(connectionFactory());
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new StringRedisSerializer());
redisTemplate.setEnableTransactionSupport(true);
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
}
@Repository
public class UserDaoImpl implements UserDao {
@Autowire
private final RedisTemplate redisTemplate;
public Object fetchUserById(String key) {
return redisTemplate.opsForHash().entries(key);
}
}
redis
spring-data-redis
0 Answers
Your Answer