egg-redis icon indicating copy to clipboard operation
egg-redis copied to clipboard

nodejs.ReplyError: NOAUTH Authentication required.

Open zhengtulymGh opened this issue 2 years ago • 0 comments

在请求接口 /test的时候,报错。redis的host、port以及password都是正确的,不知道是哪里出现了问题 egg-redis版本:^2.5.0 egg版本:^3

报错信息

2023-06-16 16:59:34,096 ERROR 60949 nodejs.ReplyError: NOAUTH Authentication required.
   at parseError (/app/node_modules/redis-parser/lib/parser.js:179:12)
   at parseType (/app/node_modules/redis-parser/lib/parser.js:302:14)
command: {"name":"info","args":[]}
pid: 60949
hostname: sz-user.local

router.js

'use strict';

/**
 * @param {Egg.Application} app - egg application
 */
module.exports = app => {
  const { router, controller } = app;
  router.get('/test', controller.home.test);
  router.get('/', controller.home.index);
};

controller/home.js

'use strict';

const { Controller } = require('egg');

class HomeController extends Controller {
  async index() {
    const { ctx } = this;
    ctx.body = 'hi, egg';
  }

  async test() {
    const { ctx, app } = this;
    console.log('test start')
    // set
    await app.redis.set('foo', 'bar');
    // get
    ctx.body = await app.redis.get('foo');
  }
}

module.exports = HomeController;

plugin.js

'use strict';

/** @type Egg.EggPlugin */
module.exports = {
  // had enabled by egg
  // static: {
  //   enable: true,
  // }
  redis: {
    enable: true,
    package: 'egg-redis'
  }
};

config.default.js

/* eslint valid-jsdoc: "off" */

'use strict';

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {};


  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1686821889236_483';

  // add your middleware config here
  config.middleware = [];

  config.redis ={
    // Redis: require('ioredis'),
    client: {
      cluster: true,
      nodes: [{
        host: '*.*.*.*.',
        port: '*',
        password: '*******',
        db: 0,
        // autoResubscribe: true
      }]
    },
  }

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };
  

  return {
    ...config,
    ...userConfig
  };
};

zhengtulymGh avatar Jun 16 '23 09:06 zhengtulymGh