I had tried using php it’s giving expected result
<?php
$redis = new redis();
$redis->connect("192.16.200.38", 6378);
$redis->select(2);
$result = $redis->hGetAll($key . "myCode");
print_r($result);
But not giving the expected result in case of node js
const client = redis.createClient({
host: "192.16.200.38",
port: 6379
});
client.on('connect', () => {
console.log('Connected to Redis');
});
client.on('error', (err) => {
console.log("nnError" + err);
})
await client.connect();
await client.select(2);
const x = await client.hGetAll(key + 'myCode');
console.log(x);
But it’s not giving the result in case of node instead of this it’s giving
- Server started on port 8000
- Connected to Redis
- [Object: null prototype] {}
2
Answers
hGetAll
will return an object in your case, on selected DB 2the key you are accessing is not present that’s why it is returning an empty object.
on PHP version you are connecting to redis server on port 6378 and on node you are accessing 6379.
check and verify if key you are trying to access is present or not in redis server running on port 6379
That is the default behaviour of redis in node.js. If the key does not exist, it will return {}
Since you get results in php with this
($key . "myCode")
that means this key definitely exist.In node.js
console.log(key + 'myCode')
to see if that key is same as above.