Javascript Node.js、wordpress、redis

Javascript Node.js、wordpress、redis,javascript,node.js,express,redis,Javascript,Node.js,Express,Redis,我需要从节点服务器中的Redis获取数据,并将其发送到Wordpress布局。我尝试了以下操作,但是数据似乎没有被发送 var express = require('express'); var app = express(); var redis = require('redis'); var client = redis.createClient(); //creates a new client client.on('connect', function () { console

我需要从节点服务器中的Redis获取数据,并将其发送到Wordpress布局。我尝试了以下操作,但是
数据
似乎没有被发送

var express = require('express');
var app = express();
var redis = require('redis');
var client = redis.createClient(); //creates a new client

client.on('connect', function () {
    console.log('connected');
});

data = [];

client.set(['first', 'Oleh']);
client.set(['second', 'Ivan']);
client.set(['thirt', 'Andriy']);
client.set(['fourth', 'Olena']);
client.set(['fifth', 'Kristy']);
client.set(['sixth', 'Irina']);

client.get('first', function (err, reply) {
    console.log(reply);
    data.push(reply);
});

client.get('second', function (err, reply) {
    console.log(reply);
    data.push(reply);
});

client.get('thirt', function (err, reply) {
    console.log(reply);
    data.push(reply);
});

client.get('fourth', function (err, reply) {
    console.log(reply);
    data.push(reply);
});

client.get('fifth', function (err, reply) {
    console.log(reply);
    data.push(reply);
});

client.get('sixth', function (err, reply) {
    console.log(reply);
    data.push(reply)
});

app.get('http://localhost/wordpress/', function (req, res) {

    res.type('application/json'); // set content-type
    res.send(this.data); // send text response
    console.log(this.data);
});

app.listen(process.env.PORT || 4730);

看来你的范围不正确
this.data
指的是
函数(req,res){}
而不是全局范围


尝试执行
res.json(data)
并删除
res.type()
,因为
res.json
已经为您解决了这个问题。

您能告诉我们您的想法吗?请编辑您的问题,并将其添加到那里。如果我转到url“”,我会得到json并在页面中看到,但如果我用wordpress发送数据,这样的问题通常不容易解决。至少你现在已经解决了一件事,试着问一个新问题,提供更多关于你的Wordpress设置、插件和你想要实现的东西的细节。