繁体   English   中英

AWS elasticache - Redis:无法调试 Redis 错误

[英]AWS elasticache - Redis: Unable to debug for Redis errors

我们正在使用带有 Redis 的 AWS Elasticache 实现缓存,并使用 nodejs 将其与 Redis 连接。 创建一个有序集合并在其中添加和获取元素。 它在本地机器上运行良好,而在暂存上不工作。 这是代码,

const redis = require("redis")
const redisOption = {
    host: redis_host_url,
    port: redis_port
}
let client = redis.createClient(redisOption);
console.log(client);
client = promisify(client.zadd).bind(client);
console.log(client);
let response = await client("abc",1,"string_to_add");
console.log(response);

在本地机器上打印响应,但 Lambda 日志不包含最后一个控制台。 客户是:

RedisClient {
  _events: [Object: null prototype] { newListener: [Function] },
  _eventsCount: 1,
  _maxListeners: undefined,
  address: 'XXXXXXXXXX:6379',
  connection_options: { port: 6379, host: 'XXXXXXXXXX', family: 4 },
  connection_id: 0,
  connected: false,
  ready: false,
  should_buffer: false,
  command_queue:
   Denque {
     _head: 0,
     _tail: 0,
     _capacityMask: 3,
     _list: [ <4 empty items> ] },
  offline_queue:
   Denque {
     _head: 0,
     _tail: 0,
     _capacityMask: 3,
     _list: [ <4 empty items> ] },
  pipeline_queue:
   Denque {
     _head: 0,
     _tail: 0,
     _capacityMask: 3,
     _list: [ <4 empty items> ] },
  connect_timeout: 3600000,
  enable_offline_queue: true,
  retry_timer: null,
  retry_totaltime: 0,
  retry_delay: 200,
  retry_backoff: 1.7,
  attempts: 1,
  pub_sub_mode: 0,
  subscription_set: {},
  monitoring: false,
  message_buffers: false,
  closing: false,
  server_info: {},
  auth_pass: undefined,
  selected_db: undefined,
  fire_strings: true,
  pipeline: false,
  sub_commands_left: 0,
  times_connected: 0,
  buffers: false,
  options:
   { host: XXXXXXXXXX,
     port: 6379,
     socket_keepalive: true,
     socket_initial_delay: 0,
     return_buffers: false,
     detect_buffers: false },
  reply: 'ON',
  reply_parser:
   JavascriptRedisParser {
     optionReturnBuffers: false,
     optionStringNumbers: false,
     returnError: [Function: returnError],
     returnFatalError: [Function: returnFatalError],
     returnReply: [Function: returnReply],
     offset: 0,
     buffer: null,
     bigStrSize: 0,
     totalChunkSize: 0,
     bufferCache: [],
     arrayCache: [],
     arrayPos: [] },
  stream:
   Socket {
     connecting: true,
     _hadError: false,
     _handle:
      TCP {
        reading: false,
        onread: [Function: onStreamRead],
        onconnection: null,
        [Symbol(owner)]: [Circular] },
     _parent: null,
     _host: null,
     _readableState:
      ReadableState {
        objectMode: false,
        highWaterMark: 16384,
        buffer: BufferList { head: null, tail: null, length: 0 },
        length: 0,
        pipes: null,
        pipesCount: 0,
        flowing: true,
        ended: false,
        endEmitted: false,
        reading: false,
        sync: true,
        needReadable: false,
        emittedReadable: false,
        readableListening: false,
        resumeScheduled: true,
        paused: false,
        emitClose: false,
        autoDestroy: false,
        destroyed: false,
        defaultEncoding: 'utf8',
        awaitDrain: 0,
        readingMore: false,
        decoder: null,
        encoding: null },
     readable: false,
     _events:
      [Object: null prototype] {
        end: [Array],
        connect: [Function],
        data: [Function],
        error: [Function],
        close: [Function],
        drain: [Function] },
     _eventsCount: 6,
     _maxListeners: undefined,
     _writableState:
      WritableState {
        objectMode: false,
        highWaterMark: 16384,
        finalCalled: false,
        needDrain: false,
        ending: false,
        ended: false,
        finished: false,
        destroyed: false,
        decodeStrings: false,
        defaultEncoding: 'utf8',
        length: 0,
        writing: false,
        corked: 0,
        sync: true,
        bufferProcessing: false,
        onwrite: [Function: bound onwrite],
        writecb: null,
        writelen: 0,
        bufferedRequest: null,
        lastBufferedRequest: null,
        pendingcb: 0,
        prefinished: false,
        errorEmitted: false,
        emitClose: false,
        autoDestroy: false,
        bufferedRequestCount: 0,
        corkedRequestsFree: [Object] },
     writable: true,
     allowHalfOpen: false,
     _sockname: null,
     _pendingData: null,
     _pendingEncoding: '',
     server: null,
     _server: null,
     [Symbol(asyncId)]: 7,
     [Symbol(lastWriteQueueSize)]: 0,
     [Symbol(timeout)]: null,
     [Symbol(kBytesRead)]: 0,
     [Symbol(kBytesWritten)]: 0 } }

甚至在 promisify 工作之后的控制台,并且正在打印:

[Function: bound zadd]

但是最后一个控制台没有打印任何东西。 我无法调试,因为 AWS Elasticache 不提供 Redis 的日志。

您需要在您的 AWS 设置和本地~/.ssh/config中定义堡垒主机

Host your-bastion-host
    HostName <IP_of_your_bastion_host_on_EC2>
    Port 22
    User ec2-user
    IdentityFile ~/.ssh/<your_key_file_for_bastion_host>.pem
    ForwardAgent yes
    AddKeysToAgent yes

使用堡垒主机和 VPC,您可以通过 SSH 端口转发连接到 AWS Elasticache 服务...

ssh your-bastion-host -Cv -N -L 6390:ec-replication-group-xyz.amazonaws.com:6379

..和“redis-cli”工具(如果您已经在本地安装了 Redis 服务器,则将 Redis 端口 6379 转发到本地不同的端口是有意义的)

redis-cli -h localhost -p 6390 
info
monitor

然后你可以在“redis-cli”中使用monitor命令显示Redis服务器处理的每条命令,使用info命令获取Redis服务器最重要的信息和统计信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM