2

I'm converting some code that used hashmaps to redis. I ran into an issue when trying to duplicate the Hashmap function .values().

With hashmaps:

 var hTest = new HashMap();
 hTest.set('1','hello');
 hTest.set('2','world'});
 console.log(hTest.values());

Outputs: ['hello','world']

But Redis doesn't seem to have an equivalent. Closest I have found was:

client.hset("rTest", "1", 'hello'); 
client.hset("rTest", "2", 'world'});
client.hgetall("rTest",function(err, values){
 console.log(values)
});

Outputs {'1','hello','2','world'}

I know I can create a for loop and cycle through the reply but I'm hoping there's a command similar to the hashmap.values() one.

asked Mar 22, 2017 at 14:44

1 Answer 1

4

You can use HVALS commands to get all values in the hash.

However, if the hash is very large, it's always a bad idea to call HVALS or HGETALL. It might block Redis for a long time, since Redis is single-threaded.

Instead, you can use HSCAN to incrementally iterate the hash. And that should be the recommended way for getting all values of a large hash.

answered Mar 22, 2017 at 15:09
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. The maps I'm dealing with should never get very large, a couple of values at most so HVALS will work. (I'm sure I just jinxed myself and this map will grow to a couple million records now now)

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.