2

Is it not possible to store an array of objects or a list of objects via Redis 5.0?

I can only make it work - if I first convert the array/list to JSON-format like this:

redis.set('persons', JSON.stringify(array_of_persons)
const persons = JSON.parse(await redis.get('persons'));

OR

redis.hset('my_list', 'persons', JSON.stringify(array_of_persons));
const persons = JSON.parse(await redis.hget('my_list', 'persons'));

But there is a lot of overhead to continuously stringify/parse big collections in javascript when I need to add/update/remove objects from the collections - so how do I performance optimize this code - if it can't be done in a more "native" way in Redis v. 5.0?

1 Answer 1

4

You could put them in a List in Redis instead of a String. Try:

redis.lpush('persons', ...array_of_persons)

For the full complement of List commands, check out: https://redis.io/commands#list

Sign up to request clarification or add additional context in comments.

2 Comments

I simply can't remember the details anymore - about this issue... but back then I apparently couldn't get anything to work out well ... but this seems pretty easy :) Also crazy it took someone months to come up with an answer to my question :D
I just dropped into StackOverflow, since it has been a while, and this question was unanswered. So I answered it. Didn't even look at the date. Hopefully it helps someone down the road!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.