<p>I have a business case where I want to access a clustered Redis cache from one account (let's say account A) to an account B.</p>
<p>I have used the solution mentioned in the below link and for the most part, it works <a href="https://medium.com/@programmerohit/accessing-aws-elasticache-redis-from-multiple-aws-accounts-via-aws-privatelink-8938891bec6c" rel="nofollow noreferrer">Base Solution</a></p>
<p>The base solution works fine if I am trying to access the clustered Redis via <code>redis-py</code> however if I try to use it with <code>redis-py-cluster</code> it fails.</p>
<p>I am testing all this in a staging environment where the Redis cluster has only one node but in the production environment, it has two nodes, so the <code>redis-py</code> approach will not work for me.</p>
<p>Below is my sample code</p>
<pre><code>redis = &quot;3.5.3&quot;
redis-py-cluster = &quot;2.1.3&quot;
==============================


from redis import Redis
from rediscluster import RedisCluster

respCluster = 'error'
respRegular = 'error'

host = &quot;vpce-XXX.us-east-1.vpce.amazonaws.com&quot;
port = &quot;6379&quot;

try:
    ru = RedisCluster(startup_nodes=[{&quot;host&quot;: host, &quot;port&quot;: port}], decode_responses=True, skip_full_coverage_check=True)
    respCluster = ru.get('ABC')
except Exception as e:
    print(e)

try:
    ru = Redis(host=host, port=port, decode_responses=True)
    respRegular = ru.get('ABC')
except Exception as e:
    print(e)

return {&quot;respCluster&quot;: respCluster, &quot;respRegular&quot;: respRegular}
</code></pre>
<p>The above code works perfectly in account A but in account B the output that I got was</p>
<pre><code>{'respCluster': 'error', 'respRegular': '123456789'}
</code></pre>
<p>And the error that I am getting is</p>
<pre><code>rediscluster.exceptions.ClusterError: TTL exhausted
</code></pre>
<p>In account A we are using AWS ECS + EC2 + docker to run this and</p>
<p>In account B we are running the code in an AWS EKS Kubernetes pod.</p>
<p>What should I do to make the <code>redis-py-cluster</code> work in this case? or is there an alternative to <code>redis-py-cluster</code> in python to access a multinode Redis cluster?</p>
<p>I know this is a highly specific case, any help is appreciated.</p>
<p><strong>EDIT 1</strong>: Upon further research, it seems that TTL exhaust is a general error, in the logs the initial error is</p>
<pre><code>redis.exceptions.ConnectionError: 
Error 101 connecting to XX.XXX.XX.XXX:6379. Network is unreachable
</code></pre>
<p>Here the XXXX is the IP of the Redus cluster in Account A.
This is strange since the <code>redis-py</code> also connects to the same IP and port,
this error should not exist.</p>

Abhishek Patil
<p>So turns out the issue was due to how <code>redis-py-cluster</code> manages host and port.</p>
<p>When a new <code>redis-py-cluster</code> object is created it gets a list of host IPs from the Redis server(i.e. Redis cluster host IPs form account A), after which the client tries to connect to the new host and ports.</p>
<p>In normal cases, it works as the initial host and the IP from the response are one and the same.(i.e. the host and port added at the time of object creation)</p>
<p>In our case, the object creation host and port are obtained from the DNS name from the Endpoint service of Account B.</p>
<p>It leads to the code trying to access the actual IP from account A instead of the DNS name from account B.</p>
<p>The issue was resolved using <a href="https://github.com/Grokzen/redis-py-cluster/blob/3b68c18810c2e8cea20d7e900064b1f8ec811260/docs/client.rst#host-port-remapping" rel="nofollow noreferrer">Host port remapping</a>, here we bound the IP returned from the Redis server from Account A with IP Of Account B's endpoints services DNA name.</p>
