# How can I connect to pre-created redis instance?

**URL:** <https://discuss.ray.io/t/how-can-i-connect-to-pre-created-redis-instance/3048>\
**Category:** Ray Core\
**Created:** [July 28, 2021, 8:30am UTC](https://discuss.ray.io/t/how-can-i-connect-to-pre-created-redis-instance/3048 "2021-07-28T08:30:50Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![CraigMeng](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/craigmeng/32/1339_2.png) [@CraigMeng](https://discuss.ray.io/u/CraigMeng)\
**Post date:** [July 28, 2021, 8:30am UTC](https://discuss.ray.io/t/how-can-i-connect-to-pre-created-redis-instance/3048/1 "2021-07-28T08:30:50Z")

</div>

Hi there,

This is my first time trying Ray (ray-1.5.0), . I`m trying to setup Ray with ray.init(address=…)  
Here I have a pre-created Redis instance (well, it is Azure Redis Cache), and I give the azure redis address to address parameter.

And I see the following error from Ray:  
RuntimeError: Could not read ‘session\_name’ from GCS (redis). Has redis started correctly on the head node?

By looking the codes, I am sure the redis is connected.  
May I know how I can connect Ray to existing redis?

---

<div class="post-metadata">

**Author:** ![CraigMeng](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/craigmeng/32/1339_2.png) [@CraigMeng](https://discuss.ray.io/u/CraigMeng)\
**Post date:** [July 28, 2021, 8:38am UTC](https://discuss.ray.io/t/how-can-i-connect-to-pre-created-redis-instance/3048/2 "2021-07-28T08:38:16Z")

</div>

Sorry, I forgot to attach the full stack trace:

## 2021-07-28 08:24:50,274 INFO worker.py:801 – Connecting to existing Ray cluster at address: 10.216.188.132:6379

RuntimeError Traceback (most recent call last)  
 in   
----\> 1 ray.init(address=“10.216.188.132:6379”, \_redis\_password=“password=”)

/opt/conda/envs/ACQAPython/lib/python3.6/site-packages/ray/\_private/client\_mode\_hook.py in wrapper(\*args, \*\*kwargs)  
80 if client\_mode\_should\_convert():  
81 return getattr(ray, func. **name** )(\*args, \*\*kwargs)  
—\> 82 return func(\*args, \*\*kwargs)  
83  
84 return wrapper

/opt/conda/envs/ACQAPython/lib/python3.6/site-packages/ray/worker.py in init(address, num\_cpus, num\_gpus, resources, object\_store\_memory, local\_mode, ignore\_reinit\_error, include\_dashboard, dashboard\_host, dashboard\_port, job\_config, configure\_logging, logging\_level, logging\_format, log\_to\_driver, namespace, runtime\_env, internal\_config, \_enable\_object\_reconstruction, \_redis\_max\_memory, \_plasma\_directory, \_node\_ip\_address, \_driver\_object\_store\_memory, \_memory, \_redis\_password, \_temp\_dir, \_lru\_evict, \_metrics\_export\_port, \_system\_config, \_tracing\_startup\_hook, \*\*kwargs)  
907 shutdown\_at\_exit=False,  
908 spawn\_reaper=False,  
 → 909 connect\_only=True)  
910  
911 if driver\_mode == SCRIPT\_MODE and job\_config:

/opt/conda/envs/ACQAPython/lib/python3.6/site-packages/ray/node.py in **init** (self, ray\_params, head, shutdown\_at\_exit, spawn\_reaper, connect\_only)  
179 else:  
180 redis\_client = self.create\_redis\_client()  
 → 181 session\_name = \_get\_with\_retry(redis\_client, “session\_name”)  
182 self.session\_name = ray.\_private.utils.decode(session\_name)  
183

/opt/conda/envs/ACQAPython/lib/python3.6/site-packages/ray/node.py in \_get\_with\_retry(redis\_client, key, num\_retries)  
46 time.sleep(2)  
47 if not result:  
—\> 48 raise RuntimeError(f"Could not read ‘{key}’ from GCS (redis). "  
49 “Has redis started correctly on the head node?”)  
50 return result

RuntimeError: Could not read ‘session\_name’ from GCS (redis). Has redis started correctly on the head node?

---

<div class="post-metadata">

**Author:** ![kai](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/kai/32/3380_2.png) [@kai](https://discuss.ray.io/u/kai)\
**Post date:** [July 28, 2021, 9:42am UTC](https://discuss.ray.io/t/how-can-i-connect-to-pre-created-redis-instance/3048/3 "2021-07-28T09:42:32Z")

</div>

Hi @CraigMeng,

this seems to be a bug on our side - it seems that `ray.init()` does not initialize new ray cluster correctly.

The workaround here is to first start Ray via the CLI: `ray start --head --address 10.216.188.132:6379 --redis-password "password"`. After that you can use `ray.init()` as you do in your script.

cc @Alex

---

<div class="post-metadata">

**Author:** ![kai](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/kai/32/3380_2.png) [@kai](https://discuss.ray.io/u/kai)\
**Post date:** [July 28, 2021, 9:46am UTC](https://discuss.ray.io/t/how-can-i-connect-to-pre-created-redis-instance/3048/4 "2021-07-28T09:46:47Z")

</div>

I created an issue to track this: [[core] External Redis does not work for new clusters · Issue #17400 · ray-project/ray · GitHub](https://github.com/ray-project/ray/issues/17400)

---

<div class="post-metadata">

**Author:** ![CraigMeng](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/craigmeng/32/1339_2.png) [@CraigMeng](https://discuss.ray.io/u/CraigMeng)\
**Post date:** [July 28, 2021, 9:49am UTC](https://discuss.ray.io/t/how-can-i-connect-to-pre-created-redis-instance/3048/5 "2021-07-28T09:49:26Z")

</div>

> Thank you, Kai.
> 
> I got following output by running `ray start --head --address 10.216.188.132:6379 --redis-password "password"`
> 
> ```auto
> `--head` starts a new Redis server, `--address` should not be set.
> 
> ```

Sorry, I was wrong. I run the command in my windows machine, which only installed version 1.4.

On Linux machine, I got following errors：

> /opt/conda/envs/ACQAPython/lib/python3.6/site-packages/ray/autoscaler/\_private/cli\_logger.py:61: FutureWarning: Not all Ray CLI dependencies were found. In Ray 1.4+, the Ray CLI, autoscaler, and dashboard will only be usable via `pip install 'ray[default]'`. Please update your install command.  
> “update your install command.”, FutureWarning)  
> Will use value of `--address` as remote Redis server address(es). If the primary one is not reachable, we starts new one(s) with `--port` in local.  
> Local node IP: 10.240.16.215  
> 2021-07-29 01:47:53,602 ERROR services.py:1254 – Failed to start the dashboard: Failed to start the dashboard, return code 1. The last 10 lines of /tmp/ray/session\_2021-07-29\_01-47-51\_520908\_774/logs/dashboard.log:  
> 2021-07-29 01:47:53,398 INFO dashboard.py:92 – Setup static dir for dashboard: /opt/conda/envs/ACQAPython/lib/python3.6/site-packages/ray/new\_dashboard/client/build  
> 2021-07-29 01:47:53,432 ERROR head.py:87 – Connect to GCS failed: GCS address not found., retry…
> 
> 2021-07-29 01:47:53,618 WARNING services.py:1716 – WARNING: The object store is using /tmp instead of /dev/shm because /dev/shm has only 67108864 bytes available. This will harm performance! You may be able to free up space by deleting files in /dev/shm. If you are inside a Docker container, you can increase /dev/shm size by passing ‘–shm-size=2.40gb’ to ‘docker run’ (or add it to the run\_options list in a Ray cluster config). Make sure to set this to more than 30% of available RAM.  
> [2021-07-29 01:47:53,795 C 774 774] redis\_client.cc:126: Check failed: \_s.ok() Bad status: RedisError:  
> \*\*\* StackTrace Information \*\*\*  
> ray::SpdLogMessage::Flush()  
> ray::RayLog::~RayLog()  
> ray::gcs::RedisClient::Connect()  
> ray::gcs::RedisClient::Connect()  
> ray::gcs::ServiceBasedGcsClient::Connect()  
> ray::gcs::GlobalStateAccessor::Connect()  
> \_\_pyx\_pw\_3ray\_7\_raylet\_19GlobalStateAccessor\_3connect()  
> \_PyCFunction\_FastCallDict

It seems that connecting to Redis failed.

---

<div class="post-metadata">

**Author:** ![sangcho](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/sangcho/32/425_2.png) [@sangcho](https://discuss.ray.io/u/sangcho)\
**Post date:** [July 28, 2021, 6:02pm UTC](https://discuss.ray.io/t/how-can-i-connect-to-pre-created-redis-instance/3048/7 "2021-07-28T18:02:45Z")

</div>

Connecting to pre-created Redis instance support was recently added, and not well tested. Btw, did you find any documentation about connecting external redis, or are you just trying to do this now?

---

<div class="post-metadata">

**Author:** ![CraigMeng](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/craigmeng/32/1339_2.png) [@CraigMeng](https://discuss.ray.io/u/CraigMeng)\
**Post date:** [July 29, 2021, 1:52am UTC](https://discuss.ray.io/t/how-can-i-connect-to-pre-created-redis-instance/3048/8 "2021-07-29T01:52:08Z")

</div>

@sangcho I didn`t find any documentation about connecting external redis. I thought Ray supports connecting external redis by nature.

---

<div class="post-metadata">

**Author:** ![sangcho](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/sangcho/32/425_2.png) [@sangcho](https://discuss.ray.io/u/sangcho)\
**Post date:** [July 29, 2021, 7:37pm UTC](https://discuss.ray.io/t/how-can-i-connect-to-pre-created-redis-instance/3048/9 "2021-07-29T19:37:52Z")

</div>

I see. This wasn’t supported, but we recently received a contribution. Maybe the feature is not well tested
