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.
1 Answer 1
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.