appfog 怎么用node连接自带的redis
文档没看懂
{"redis-2.2":[
{
"name":"redis-example",
"label":"redis-2.2",
"plan":"free",
"tags":["redis","redis-2.2","key-value","nosql"],
"credentials":{
"hostname":"10.7.66.164",
"host":"10.7.66.164",
"port":5004,
"password":"191dc43f-69a3-4d31-ac5e-4b66155b2e8e",
"name":"9e3f3a9c-82ba-4c2e-bc83-b498e5447251"
}
}
]}
是不是要这样写
var options = {
host: '10.7.66.164',
hostname:'10.7.66.164',
port: 5004,
prefix: 'chs-sess',
pass:这里怎么写?
还有有这里貌似没有写name的选项
}
app.use(express.cookieParser());
app.use(express.session({ store: new RedisStore(options), secret: 'zclcat' }))
还有prefix有什么用
6 回复
https://docs.appfog.com/add-ons/rediscloud#rediscloud-node
var redis = require('redis');
var url = require('url');
var redisURL = url.parse(process.env.REDISCLOUD_URL);
var client = redis.createClient(redisURL.port, redisURL.hostname, {no_ready_check: true});
client.auth(redisURL.auth.split(":")[1]);
谢谢,不过这个是在add-ons里,我选的是在service,貌似也没有输入用户名密码的,直接能用
https://docs.appfog.com/services/redis
process.env.VCAP_SERVICES
这个取到的就是 那个 json对象 var env = JSON.parse(process.env.VCAP_SERVICES); var db = env[‘redis-2.2’][0][‘credentials’]; store: new RedisStore(db); 这样就ok了,要学会看文档!
错了 var db = env[‘redis-2.2’][‘credentials’]; 没有那个[0]我是在我mysql上改的改错了
@javanode 非常感谢,我去试试