Skip to content

How can I extend the save method in the RedisSessionRepository? #2179

Closed as not planned
@ohHyunJae

Description

@ohHyunJae

When I save a session with redis,

I'd like to add custom data.

RedisSessionRepository.class
    
    ....
    
    @Override
        public void save(CustomRedisSessionRepository.RedisSession session) {
            if (!session.isNew) {
                String key = getSessionKey(session.hasChangedSessionId() ? session.originalSessionId : session.getId());
                Boolean sessionExists = this.sessionRedisOperations.hasKey(key);
                if (sessionExists == null || !sessionExists) {
                    throw new IllegalStateException("Session was invalidated");
                }
            }
            session.save();

            //I want add code..... (custom data..)
        }

So I decided to expand.

public class MyRedisSessionRepository extends RedisSessionRepository {
    
    public MyRedisSessionRepository(RedisOperations<String, Object> sessionRedisOperations) {
        super(sessionRedisOperations);
    }
    
    @Override
    public void save(RedisSessionRepository.RedisSession session) {
        super.save(session);
        //add custom data...
    }
}

But I can't. The access modifier for RedisSession is 'default'.

public class RedisSessionRepository implements SessionRepository<RedisSessionRepository.RedisSession> {

...
 final class RedisSession implements Session {
  ....
 }
..
}

So I can't extend the save method of RedisSessionRepository.

Is there any other way Or is there an expandable class?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions