spring-projects / spring-session

Spring Session
https://spring.io/projects/spring-session
Apache License 2.0
1.86k stars 1.12k forks source link

Spring session keys created in redis have different formats when running from a windows machine vs when running on a linux machine #578

Open kamal2311 opened 8 years ago

kamal2311 commented 8 years ago

Note that keys written from a spring boot spring session app running on a windows machine have these junk characters where as the keys written from an app running on a linux machine does not have these junk characters. Looks like platform specific encoding is affecting these keys.

Generated from windows machine "\xac\xed\x00\x05t\x00<spring:session:sessions:144a6b90-f6e7-44fc-b92b-ada5671ffe36"

Generated from Linux machine "spring:session:sessions:9263abe7-0557-4062-9209-a4248f7c97c7" "spring:session:sessions:dd32765e-9440-4bec-9cd9-8d8fd037ce1f"

vpavic commented 8 years ago

@kamal2311 Are you sure both scenarios use the same configuration, in particular the same serialization mechanism?

At first glance it looks like app on Windows machine uses JdkSerializationRedisSerializer whereas on Linux machine it uses StringRedisSerializer.

kamal2311 commented 8 years ago

Yes I use the same source code on both the environments. I too think the problem is in serialization but my application code does not explicitly specify platform specific serialization. Problem seems to be some where in the framework code.

    @Bean
    public RedisTemplate<Object, Object> sessionRedisTemplate(
            RedisConnectionFactory connectionFactory) {
        RedisTemplate<Object, Object> template = new RedisTemplate<Object, Object>();
        template.setKeySerializer(new StringRedisSerializer());
        template.setHashKeySerializer(new StringRedisSerializer());
        if (this.defaultRedisSerializer != null) {
            template.setDefaultSerializer(this.defaultRedisSerializer);
        }
        template.setConnectionFactory(connectionFactory);
        return template;
    }

This is the code and that is in the RedisHttpSessionConfiguration

rwinch commented 8 years ago

I have to agree with @vpavic it appears that the Windows machine uses JdkSerializationRedisSerializer whereas on Linux machine it uses StringRedisSerializer.

Can you perhaps add a debug point to both JdkSerializationRedisSerializer and StringRedisSerializer on the windows machine to see which is being used to save session ids?

kamal2311 commented 8 years ago

The debug point showed that it was StringRedisSerializer that was used on the Windows machine.

rwinch commented 8 years ago

@kamal2311 Are you using the exact same Redis instance for both the Linux and Windows app? Are you using the exact same redis client to view the results?

kamal2311 commented 8 years ago

Yes. It is the exact same redis instance (one instance) and identical spring boot app (running versions built from the same source code) in both environments.

Redis version 3.0.4.2 Windows version 7 Enterprise Linux version 2.6 Redhat enterprise

On 10 August 2016 at 14:56, Rob Winch notifications@github.com wrote:

@kamal2311 https://github.com/kamal2311 Are you using the exact same Redis instance for both the Linux and Windows app?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/spring-projects/spring-session/issues/578#issuecomment-238967782, or mute the thread https://github.com/notifications/unsubscribe-auth/AAog0dsPxROM-6EYZjL3q22pSTnwTiSJks5qeh7pgaJpZM4JUOi7 .

rwinch commented 8 years ago

@kamal2311 Thanks for the response. When I said client I meant to ask if you are using the same client to view the keys. For example, are you using the same redis-cli on the same machine to view both the Linux inserted keys and the Windows inserted keys.

kamal2311 commented 8 years ago

@rwinch oh sorry I missed the client part. Yes I am using the same redis-cli on the windows machine to view the Redis session keys.

ysjiang4869 commented 7 years ago

@kamal2311 do you have any methods to solve this problem? I have the same question , and i can't get the session using redistemplate now

tommyacm commented 7 years ago

anybody has a solution for this issue?