我在下面有一个server.php。我希望在我的频道上有监听器,这样我就可以获得我网站的实时数据。我附上了我的redis的结构。
const express = require('express');
const app = express();
var server = require('http').Server(app);
const bodyParser = require('body-parser');
const cors = require('cors');
const Redis = require('redis');
const bluebird = require('bluebird');
var routes = express.Router();
var io = require('socket.io')(server);
bluebird.promisifyAll(Redis.RedisClient.prototype);
bluebird.promisifyAll(Redis.Multi.prototype);
var Client =
Redis.createClient({
host:'159.89.5.229',
port:'6379',
socket_keepalive : true,
prefix:'resque:',
retry_strategy: function (options) {
if(options.error && options.error.code === 'ECONNREFUSED'){
return new Error({'Code':99,'Message':'Connection Lost On Redis'});
}
if(options.total_retry_time > 1000 * 60 * 60){
return new Error({'Code':100,'Message':'Retry Time Exhausted'});
}
if(options.attempt > 10){
return undefined;
}
return Math.min(options.attempt * 100 , 3000);
}
});
Client.subscribe('resque:queue:default');
Client.on("subscribe",function (channel,count) {
console.log(channel + count);
});
Client.on('message',function (chan,msg) {
console.log(msg);
});
Client.on('error',function (err) {
console.log(err);
});
此外,如果有任何消息来到我的频道,例如queue - > resque:队列:默认我想知道。有任何想法吗 ? 顺便说一句,我是redis的新手。如果有任何错误,我很抱歉