【发布时间】:2019-11-01 01:41:00
【问题描述】:
我正在尝试使用 Ruby Redis 客户端 redis-rb 连接到为集群配置的 Azure Redis 缓存。
我尝试过的:
我已使用此related question 成功连接到非集群 Azure Redis 缓存。我还可以使用它连接到群集 Azure Redis 缓存,当我尝试获取或设置密钥时,它会正确报告 MOVED:
Redis::CommandError (MOVED 1234 address_here:port_here)
我已经看到这个documentation 用于创建与cluster 的连接:
节点可以作为连接 URL 的数组传递给客户端。
nodes = (7000..7005).map { |port| "redis://127.0.0.1:#{port}" } redis = Redis.new(cluster: nodes)您还可以将选项指定为哈希。这些选项与单个服务器连接的选项相同。
(7000..7005).map { |port| { host: '127.0.0.1', port: port } }
我已经使用这些示例针对单个可用 DNS 端点构建了一个示例,该端点因以下错误而失败:
irb(main):024:0> client = Redis.new(cluster: ["redis://my-redis-cluster.redis.cache.windows.net:6379"])
...
Redis::CannotConnectError (Redis client could not connect to any cluster nodes)
我已经尝试了文档中列出的每个变体,结果相同。
问题:
Azure Cache for Redis 在单个 DNS 终结点上公开群集节点,而此 redis-rb 群集参数似乎需要已知节点终结点的集合。
是否可以使用此库连接到群集 Azure Redis 缓存?如果是这样,一个可重现的例子会是什么样子?如果 redis-rb 无法实现,但其他 Ruby Redis 客户端可以实现,我也会对该解决方案感兴趣。
【问题讨论】:
标签: ruby-on-rails ruby azure redis azure-redis-cache