egg-redis app.redis.set is not a function

Created on 15 Mar 2017  ·  10Comments  ·  Source: eggjs/egg

windows 7 install and use
ic f9sur0g 6 ee0j dee8
code:
config.default.js:
1q ej3 849v9im7bh1_q84o
plugin.js:
m 1 5tccmucd7yl3tglg_o7
app.controller.home.js:
3zo9dya9ku tnoho 8ahzd
then request:
in_khl jzdkn9uvgt 5xd5

node 7.7.2
bi w1 xxg a5kzrwtq4ytc

Most helpful comment

exports.redis = {
  client: {
    host: '127.0.0.1',
    port: 6379,
    password: '',
    db: '0',
  },
  agent:true
};

All 10 comments

不使用cluster模式不要配置到node里,而且要配置到client下。请参考 https://github.com/eggjs/egg-redis/blob/master/config/config.default.js

4a7u3qbp w u2xkbdh k
改成这样还是不行

exports.redis = {
  client: {
    host: '127.0.0.1',
    port: 6379,
    password: '',
    db: '0',
  },
  agent:true
};
'use strict';
const path = require('path');
module.exports = appInfo => {
  const config = {
      mysql : {
      // database configuration
          client: {
              // host
              host: 'localhost',
              // port
              port: '3306',
              // username
              user: 'root',
              // password
              password: 'root',
              // database
              database: 'test',
          },
          // load into app, default is open
          app: true,
          // load into agent, default is close
          agent: false,
      },  
      redis : {
      // database configuration
          default: {
              // host
              host: '127.0.0.1',
              // port
              port: '6379',
          },
          // load into app, default is open
          app: true,
          // load into agent, default is close
          agent: false,
      },
  };

  // should change to your own
  config.keys = appInfo.name + '_1489048554806_6546';

  return config;
};

mysql都没问题

add
password: '',
db: '0',
success

@jtyjty99999 thx

egg-redis app.redis.set is not a function 还是有这个问题,请问是怎么解决的?

配置问题吧,一定得有client or clients

要把 sessionRedis的name配置为空或者不配置

config.sessionRedis = {
    name: '', // 
  }

因为 egg-session-redis/app.js 里的头两行代码是这样的

  const name = app.config.sessionRedis.name;      
  const redis = name ? app.redis.get(name) : app.redis;

一个redis实例, sessionRedis配置中不需要指定实例名,即

config.redis = {
    client: {
      host: '127.0.0.1',
      port: 6379,
      password: '',
      db: '0',
    },
  };
  config.sessionRedis = {
    // name: 'session', // 这里不要指定name
  };

如果redis有多个实例,sessionRedis配置中的name需要指定一个实例名

config.redis = {
  clients: {
    foo: {                 // instanceName. See below
      port: 6379,          // Redis port
      host: '127.0.0.1',   // Redis host
      password: 'auth',
      db: 0,
    },
    bar: {
      port: 6379,
      host: '127.0.0.1',
      password: 'auth',
      db: 1,
    },
  }
  config.sessionRedis = {
    name: 'foo', 
  };

看源码就知道了: https://github.com/eggjs/egg-session-redis/blob/master/app.js#L9

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lvgg3271 picture lvgg3271  ·  3Comments

zhaofinger picture zhaofinger  ·  3Comments

yuu2lee4 picture yuu2lee4  ·  3Comments

Azard picture Azard  ·  3Comments

bupafengyu picture bupafengyu  ·  3Comments