Hapi缓存引擎,我可以设置,但我无法得到

时间:2016-11-27 15:40:58

标签: javascript redis hapijs

我使用yar作为我的会话插件以及catbox-redis。 这是我的配置:

const Hapi = require('hapi');
const yar  = require('yar');
const hapiServer = new Hapi.Server({
  cache: {
    engine: require('catbox-redis'),
    host: redisAddress,
    port: redisPort
  }
});

hapiServer.connection({
    host: hapiHostAddress,
    port: hapiPort
});

hapiServer.route({
  method: 'GET',
  path: '/test/{key}/{value}',
  handler: function (request, reply) {

      // In MongoDB, this data will be stored in the
      // "!yar" collection within the "hapi-cache" database.
      var data = {};
      data[request.params.key] = request.params.value;
      request.yar.set('example', data);
      return reply(request.yar.get('example'));
  }
});

const yarOptions = {
    storeBlank: false,
    maxCookieSize: 0,
    cache: {
      expiresIn: 24 * 60 * 60 * 1000
    },
    cookieOptions: {
        password: 'the-password-must-be-at-least-32-characters-long',
        isSecure: true
    }
};

hapiServer.register({
  register: yar,
  options: yarOptions
}, function (err) {

  // start your hapiServer after plugin registration
  hapiServer.start(function (err) {
    console.log('info', 'Server running at: ' + hapiServer.info.uri)
  })
})

问题是request.yar.get('example')会返回正确的数据,但它不会使用redis(我用redis-cli monitor监视redis),即使request.yar.set('example', data)将数据保存到redis。< / p>

0 个答案:

没有答案