spring-projects / spring-projects/spring-session
Unreadable session after serialization
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.9k
- Forks
- 1.2k
- Avg merge
- 4h 27m
- Merged PRs (30d)
- 55
Description
I use Spring session with a Redis repository.
I also use the same Redis to store cache data.
It works fine but I the session attributes that are storred in Redis are unreadable.
When I try to read the content of the repository, I see this :
http://img11.hostingpics.net/pics/492480redisexpiration.png
Here is my configuration classes :
@Configuration
@EnableRedisHttpSession
public class SessionRepositoryConfig {
@Value("${spring.redis.host}")
private String redisHostName;
@Value("${spring.redis.port}")
private Integer redisPort;
@Value("${spring.redis.expiration.short}")
private Integer redisExpirationShort;
@Value("${spring.redis.expiration.medium}")
private Integer redisExpirationMedium;
@Value("${spring.redis.expiration.long}")
private Integer redisExpirationLong;
@Bean
JedisConnectionFactory jedisConnectionFactory() {
JedisConnectionFactory factory = new JedisConnectionFactory();
factory.setHostName(redisHostName);
factory.setPort(redisPort);
factory.setUsePool(true);
return factory;
}
@Bean
@Order(value = 0)
public FilterRegistrationBean sessionRepositoryFilterRegistration(SessionRepositoryFilter springSessionRepositoryFilter) {
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
filterRegistrationBean.setFilter(new DelegatingFilterProxy(springSessionRepositoryFilter));
filterRegistrationBean.setUrlPatterns(Arrays.asList("/*"));
return filterRegistrationBean;
}
}
@Configuration
@EnableCaching
public class RedisConfiguration extends CachingConfigurerSupport {
@Primary
@Bean
public RedisTemplate<String,ExpiringSession> redisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, ExpiringSession> template = new RedisTemplate<>();
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
template.setHashValueSerializer(new LdapFailAwareRedisObjectSerializer());
template.setConnectionFactory(connectionFactory);
return template;
}
@Bean
public KeyGenerator keyGenerator() {
return (target, method, params) -> {
StringBuilder sb = new StringBuilder();
sb.append(target.getClass().getName());
sb.append(method.getName());
for (Object obj : params) {
sb.append(obj.toString());
}
return sb.toString();
};
}
}
I use a custom serializer because I had an issue with the serialization of ldap information (http://stackoverflow.com/questions/32751094/spring-boot-with-session-redis-serialization-error-with-bad-active-directory-lda).
Any idea why I can't read content of the redis database ?
I think this is a serialization issue but I don't find any solution.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the two configuration classes shown, especially the RedisTemplate serializer settings and the @EnableRedisHttpSession setup. Trace which serializer Spring Session uses for its Redis hashes and compare it with the custom hash serializer; done means identifying why the stored session data is unreadable and documenting a supported configuration or limitation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, redis, spring
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100