Skip to content

Save session on Redis RedisSession.saveDelta #311

@oassuncao

Description

@oassuncao

I'm using Spring Session version 1.0.2.RELEASE and I found a problem when RedisSession save delta

If you add a new value on session (RedisSession) the session save correctly on Redis, because we have this code below:

        public void setAttribute(String attributeName, Object attributeValue) {
            cached.setAttribute(attributeName, attributeValue);
            delta.put(getSessionAttrNameKey(attributeName), attributeValue);
        }

But if in other request I get a object in this session, change some property of this object, the session on redis is not updated.

The problem is when we create RedisSession passing MapSession, this map is setter on variable "cached" but the values of "cached" doesn't pass to "delta"

Example to reproduce the problem:
POJO

public class NamePOJO implements Serializable {
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

Controller

    ...
    @RequestMapping(value = "/changeSession/{value}")
    public void changeOnSession(@PathVariable(value  = "value") String value, HttpServletRequest request) throws IOException {
        final String sessionName = "SESSION_NAME";

        NamePOJO oldVersion;
        if (request.getSession().getAttribute(sessionName) == null) {
            oldVersion = new NamePOJO();
            oldVersion.setName(value);
            request.getSession().setAttribute(sessionName, oldVersion);
        }

        oldVersion = (NamePOJO)request.getSession().getAttribute(sessionName);

        log.info(String.format("Old name %s new name %s", oldVersion.getName(), value));
        oldVersion.setName(value);
    }
    ...

1* Request (/changeSession/Test)
Output: Old name Test new name Test
2* Request (/changeSession/Changed)
Output: Old name Test new name Changed
3* Request (/changeSession/Changed)
Output: Old name Test new name Changed

On the 3* request, the old name doesn't changed

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions