Reputation: 1972
I'm making an app which uses Redis. It works perfectly on my computer running Ubuntu 12.04, but on CloudFoundry it gives me an error.
Here is the code for the app:
var
http = require("http"),
redis = require("redis"),
cf = require("cloudfoundry");
cf.cloud;
if (cf.redis["myredisservice"]) {
var rport = cf.redis["myredisservice"].credentials.port;
var rhost = cf.redis["myredisservice"].credentials.hostname;
} else {
var rport = 6379;
var rhost = "127.0.0.1";
}
http.createServer(function(req, res) {
var client = redis.createClient(rport, rhost);
res.writeHead(200, {"Content-Type": "text/html"});
client.on("error", function(error) {
res.write("Error: " + error);
});
res.write("Setting key 1<br>");
client.set("key1", "My 1st String!", redis.print);
res.write("Getting key1<br>");
client.get("key1", function(error, reply) {
res.write("Results for key1<br>");
res.write(reply);
client.end();
res.end();
});
}).listen(cf.port || 3000);
On CloudFoundry, when I run this app it gives me this output:
Setting key 1
Getting key1
Error: Error: Ready check failed: ERR operation not permitted
I can confirm that its connecting to the Redis service using the port and hostname specified by CloudFoundry.
So I think its failing because of one of those commands. :(
Can anyone tell me, why is this error happening?
Thanks. :D
Upvotes: 0
Views: 629
Reputation: 1149
You need to authenticate to redis as well. Try this:
var
http = require("http"),
redis = require("redis"),
cf = require("cloudfoundry");
cf.cloud;
if (cf.redis["myredisservice"]) {
var rport = cf.redis["myredisservice"].credentials.port;
var rhost = cf.redis["myredisservice"].credentials.hostname;
var rpass = cf.redis["myredisservice"].credentials.password;
} else {
var rport = 6379;
var rhost = "127.0.0.1";
}
http.createServer(function(req, res) {
var client = redis.createClient(rport, rhost);
client.auth(rpass);
res.writeHead(200, {"Content-Type": "text/html"});
client.on("error", function(error) {
res.write("Error: " + error);
});
res.write("Setting key 1<br>");
client.set("key1", "My 1st String!", redis.print);
res.write("Getting key1<br>");
client.get("key1", function(error, reply) {
res.write("Results for key1<br>");
res.write(reply);
client.end();
res.end();
});
}).listen(cf.port || 3000);
Upvotes: 3