gpt4 book ai didi

node.js - 通过 Node.JS 连接 RedisToGo

转载 作者:IT老高 更新时间:2023-10-28 23:09:19 26 4
gpt4 key购买 nike

我将 Redis To Go 与 https://github.com/mranney/node_redis 结合使用图书馆。 Redis 给了我一个看起来像 redis://me:978287c0b670694673d045f08b2e0371@icefish.redistogo.com:9393 但我不知道如何使用它作为 createClient() 只取主机和端口。

最佳答案

我相信您所拥有的 URL 的方案是:

redis://username:password@host:port.

我不相信 username 被使用。 node_redis 提供了两种登录方法:createClientauthreadme中有详细信息,但这里是相关部分供引用:

redis.createClient(port, host, options)

Create a new client connection. port defaults to 6379 and host defaults to 127.0.0.1. If you have redis-server running on the same computer as node, then the defaults for port and host are probably fine. options in an object with the following possible properties:

  • parser: which Redis protocol reply parser to use. Defaults to hiredis if that module is installed. This may also be set to javascript.
  • return_buffers: defaults to false. If set to true, then bulk data replies will be returned as node Buffer objects instead of JavaScript Strings.

createClient() returns a RedisClient object that is named client in all of the examples here.

client.auth(password, callback)

When connecting to Redis servers that require authentication, the AUTH command must be sent as the first command after connecting. This can be tricky to coordinate with reconnections, the ready check, etc. To make this easier, client.auth() stashes password and will send it after each connection, including reconnections. callback is invoked only once, after the response to the very first AUTH command sent.

关于node.js - 通过 Node.JS 连接 RedisToGo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7290118/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com