连接到R中的redis群集
假设redis服务器有几个主机和端口,如 10.0.1.1:6381 10.0.1.1:6382 10.0.1.2:6381 10.0.1.2:6382 如何配置连接到R中的redis群集,r,redis,R,Redis,假设redis服务器有几个主机和端口,如 10.0.1.1:6381 10.0.1.1:6382 10.0.1.2:6381 10.0.1.2:6382 如何配置redux::hiredis() 我有谷歌,但找不到解决方案。我注意到,redis_config函数的db参数上有一条注释,带有“请勿在redis集群上下文中使用”,因此我想知道这是连接集群的一种方式。此外,我还尝试通过redis://10.0.1.1:6381,10.0.1.1:6382,10.0.1.2:6381,10.0.1.2:
redux::hiredis()
我有谷歌,但找不到解决方案。我注意到,redis_config
函数的db
参数上有一条注释,带有“请勿在redis集群上下文中使用”,因此我想知道这是连接集群的一种方式。此外,我还尝试通过redis://10.0.1.1:6381,10.0.1.1:6382,10.0.1.2:6381,10.0.1.2:6382
到url
参数,但仍然失败
有什么建议吗?或者您会推荐其他软件包吗?我的初始解决方案是根据错误消息编写一个指向正确节点的函数
check_redis <- function(key = "P10000", host = "10.0.1.1", port = 6381) {
r <- redux::hiredis(host = host, port = port)
status <- tryCatch(
{
r$EXISTS(key = key)
},
error = function(e){
address <- str_match(e$message,
"[0-9]+.[0-9]+.[0-9]+.[0-9]+:[0-9]+")
host <- str_split(address, ":", simplify = T)[1]
port <- str_split(address, ":", simplify = T)[2]
return(list(host = host, port = port))
}
)
if (is.list(status)) {
r <- redux::hiredis(host = status$host, port = status$port)
}
return(r)
}
检查\u redis