Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
连接到R中的redis群集_R_Redis - Fatal编程技术网

连接到R中的redis群集

连接到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:

假设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: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