Skip to content
This repository has been archived by the owner on Mar 2, 2024. It is now read-only.

incorrect handling of removed array indexes and object properties #24

Closed
fpizzo20 opened this issue Apr 15, 2021 · 2 comments
Closed

incorrect handling of removed array indexes and object properties #24

fpizzo20 opened this issue Apr 15, 2021 · 2 comments
Assignees
Labels

Comments

@fpizzo20
Copy link

I've found a strage behavior of the .set() method working with arrays.

The strage and not documented behavior is that if an array becomes shorter than the last stored in redis, the last few keys are note deleted.

Test case:

const client = this.redisService.getClient();
const usersMap = new JSONCache<number[]>(client);
const arr1 = [1,2,3];
usersMap.set('test', arr1);

let arr2 = usersMap.get('test');

arr2  = arr2 .filter(el=> {
    return el % 2 == 1;
});

// arr2 = [ 1, 3 ]

usersMap.set('test', arr2);

const arr3 = usersMap.get('test');

// arr3 = [ 1, 3, 3 ]

This 'bug' happens because this library uses hmset redis command, that does only upsert but does not remove missing keys.

This library offerse the possibility to retrieve partial objects, so is not possibile to remove missing object props / array keys on set.

I think that a big disclaimer on this behavior should be added to the docs.

Would you accept a pull request that adds some new methods to allow a user to 'set and replace with delete missing props' objects in this cache in the stored objects are very little?

Thanks
Francesco

@AkashBabu
Copy link
Owner

@fpizzo20 thanks for reporting this bug.
Yes you are most welcome to raise a PR, but will be accepted only with the corresponding test cases

@AkashBabu AkashBabu added the bug label May 15, 2021
@AkashBabu AkashBabu self-assigned this May 15, 2021
@AkashBabu
Copy link
Owner

Please upgrade your library to v6.0.0

Also please pay attention to migration guide

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants