I've just installed a redis client for my node application. Package information is as follows:
me@mydevbox:/var/www/html/node/test$ cat package.json
{
"name": "test",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"body-parser": "~1.13.2",
"cookie-parser": "~1.3.5",
"debug": "~2.2.0",
"ejs": "~2.3.3",
"express": "~4.13.1",
"morgan": "~1.6.1",
"redis": "^2.6.2",
"serve-favicon": "~2.3.0"
}
}
I need to run the following command in my node js application:
127.0.0.1:6379> SCAN 0 match widget:914*
1) "0"
2) 1) "widget:9145090003_13:00_17:00"
2) "widget:9145090003_00:00_00:00"
3) "widget:9145090003_08:00_12:00"
127.0.0.1:6379>
But I've been reading the docs and it's not clear how to do this. So far, using the samples, I've written the following code:
var client = require('redis').createClient();
client.on('error', function (err) {
console.log('Error ' + err);
});
But i haven't found a generic method that allows me to send various Redis commands. This is the reference that I'm using:
https://www.npmjs.com/package/redis
I'm currently googling around to see what other references I can find... but any suggestions would be appreciated.
Thanks
EDIT 1
I've tried the send_command, and I'm getting something back... but I don't quite know how to query the object. It feels as though it's empty...
Here's what I've tried:
client.send_command("SCAN", [0,"MATCH", "WIDGET:914*"], function(err, reply) {
console.log(reply[0].length);
console.log(reply[1].length);
});
That returns:
me@mydev:/var/www/html/node/test$ DEBUG=test:* npm start
> test@0.0.0 start /var/www/html/node/test
> node ./bin/www
attempting to scan ...
translatedid:server Listening on port 3000 +0ms
1
0
I also tried this:
client.send_command("SCAN", [0,"MATCH", "WIDGET:914*"], function(err, reply) {
for (var i = 0; i < reply.length; i++) {
console.log("variable type for item " + i + " is: " + typeof(reply));
console.log("properties for item " + i + " are: " + Object.getOwnPropertyNames(reply[i]).sort());
}
});
Which returns:
> test@0.0.0 start /var/www/html/node/test
> node ./bin/www
attempting to scan ...
test Listening on port 3000 +0ms
variable type for item 0 is: object
properties for item 0 are: 0,length
variable type for item 1 is: object
properties for item 1 are: length
But I can't seem to figure out how to get at my keys.
EDIT 2
I had to change this:
client.send_command("SCAN", [0,"MATCH", "WIDGET:914*"], function(err, reply) {
to this:
client.send_command("SCAN", [0,"MATCH", "widget:914*"], function(err, reply) {
Stupid mistake.