Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

save method is resetting existing expire value in case of update #236

Open
vhochstein opened this issue May 24, 2024 · 1 comment
Open
Labels
bug Something isn't working

Comments

@vhochstein
Copy link

If I update an existing key, which has an expire value set using save method, afterwards expire is reset to -1.

create:

const ecareSession = await ecareSessionRepository.save(req.params.sessionid, req.body);
const ttlInSeconds = 1 * 60 * 60; // 1 hours
 await ecareSessionRepository.expire(ecareSession[EntityId], ttlInSeconds);

update:

const ecareSession = await ecareSessionRepository.save(req.params.sessionid, req.body);
const key = ecareSession[EntityKeyName];
const ttl = await redisUtil.redisClient.ttl(key);

ttl is -1, expected round about 3599

const ecareSessionSchema = new Schema('ecare-session', {
        data: { type: 'string' }
    },
    {
        dataStructure: 'HASH',
        idStrategy: myRedisIdGenerator,
    }
);
@guyroyse guyroyse added the bug Something isn't working label Jun 14, 2024
@guyroyse
Copy link
Contributor

Yep. That's a bug. Might be hard to sort out as internally as the code deletes and re-adds the key using UNLINK and HSET. I did this because calling HSET will overlay the existing fields in the Hash and this leaves existing fields in place. So, if you removed a field in your data, it would not be in your JavaScript object but will still be in Redis.

I'll have to add a check to see if there is a TTL before doing this and reapply it. Or I'll need to look at all the fields that are currently there and the ones in the JavaScript object being written, diff them, and call HDEL on the offending fields.

Frankly, both are a little ugly.

JSON shouldn't have this problem as I don't delete beforehand.

Thanks for the catch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants