通过 Node.JS 连接到 RedisToGo [英] Connecting to RedisToGo through Node.JS

查看:50
本文介绍了通过 Node.JS 连接到 RedisToGo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 Redis To Go 与 https://github.com/mranney/node_redis 库结合使用.Redis 给了我一个看起来像 redis://me:978287c0b670694673d045f08b2e0371@icefish.redistogo.com:9393 的网址,但我不知道如何将它用作 createClient()> 只需要主机和端口.

I'm using Redis To Go in combination with the https://github.com/mranney/node_redis library. Redis gives me a url that looks like redis://me:978287c0b670694673d045f08b2e0371@icefish.redistogo.com:9393 but I don't know how to use it as createClient() only takes the host and the port.

推荐答案

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

I believe that the scheme for the URL you have is:

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

我不认为使用了 username.node_redis 提供了两种用于登录的方法:createClientauth.自述文件中有详细信息,但这里有相关部分供参考:

I don't believe username is used. node_redis provides two methods that you'll use to log in: createClient and auth. There are details in the readme, but for reference here is the relevant portion:

创建一个新的客户端连接.port 默认为 6379host默认为 127.0.0.1.如果你有 redis-server 在运行与节点相同的计算机,则端口和主机的默认值是可能还好.对象中的 options 具有以下可能属性:

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:使用哪个Redis协议回复解析器.默认为hiredis 如果安装了该模块.这也可以设置为javascript.
  • return_buffers:默认为 false.如果设置为 true,则批量数据回复将作为节点缓冲区对象而不是JavaScript 字符串.
  • 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() 返回一个名为 clientRedisClient 对象在此处的所有示例中.

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

当连接到需要身份验证的 Redis 服务器时,AUTH 命令必须作为连接后的第一条命令发送.这可能很难与重新连接、就绪检查、等等.为了使这更容易,client.auth() 隐藏 password 并将在每次连接后发送,包括重新连接.回调是仅在响应第一个 AUTH 命令后调用一次发送.

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 连接到 RedisToGo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆