Skip to content
This repository was archived by the owner on Nov 21, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 21 additions & 29 deletions acapy_cache_redis/v0_1/redis_base_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
from aries_cloudagent.core.profile import Profile
from aries_cloudagent.core.error import BaseError
from redis.asyncio import RedisCluster
from redis.exceptions import RedisError, RedisClusterException, ResponseError
from redis.exceptions import RedisError, RedisClusterException
from typing import Any, Sequence, Text, Union
from uuid import uuid4

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -82,33 +81,26 @@ async def check_for_redis_cluster(self):
reassign redis to redis.asyncio.RedisCluster client.

"""
try:
# Execute a redis SET command on a fake test_key prefix with b""
# value. In case, connection string is that of a single redis
# host then it will return None as it doesn't exists. Otherwise,
# it will raise a MOVED error.
fake_test_key = f"test_key_{str(uuid4())}"
await self.redis.set(fake_test_key, b"", ex=1)
except ResponseError as err:
if "MOVED" in str(err):
self.redis = self.root_profile.inject_or(RedisCluster)
if not self.redis:
self.redis = RedisCluster.from_url(
self.connection,
max_connections=self.max_connections,
username=self.username,
password=self.password,
)
# Binds RedisCluster cluster instance, so that it is
# accessible to redis_queue plugin.
LOGGER.info(
"Found redis connection string correspond to a cluster node,"
" reassigning redis to redis.asyncio.RedisCluster client."
)
self.root_profile.injector.bind_instance(RedisCluster, self.redis)
await self.redis.ping(target_nodes=RedisCluster.PRIMARIES)
else:
LOGGER.info("Using an existing provided instance of RedisCluster.")
cluster_info = await self.redis.info("cluster")
if "cluster_enabled" in cluster_info and cluster_info["cluster_enabled"] == 1:
self.redis = self.root_profile.inject_or(RedisCluster)
if not self.redis:
self.redis = RedisCluster.from_url(
self.connection,
max_connections=self.max_connections,
username=self.username,
password=self.password,
)
# Binds RedisCluster cluster instance, so that it is
# accessible to redis_queue plugin.
LOGGER.info(
"Found redis connection string correspond to a cluster node,"
" reassigning redis to redis.asyncio.RedisCluster client."
)
self.root_profile.injector.bind_instance(RedisCluster, self.redis)
await self.redis.ping(target_nodes=RedisCluster.PRIMARIES)
else:
LOGGER.info("Using an existing provided instance of RedisCluster.")

def _getKey(self, key: Text) -> Text:
return f"{self.prefix}:{key}"
Expand Down
60 changes: 30 additions & 30 deletions int/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion int/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "acapy-cache-redis-int-tests"
version = "0.1.0"
description = "Integration tests for ACA-Py Redis Cache Plugin"
authors = ["Colton Wolkins <colton@indicio.tech"]
authors = ["Colton Wolkins <colton@indicio.tech>", "Kim Ebert <kim@indicio.tech>", "Alex Walker <alex.walker@indicio.tech>"]

[tool.poetry.dependencies]
python = "^3.9"
Expand Down
6 changes: 2 additions & 4 deletions int/tests/cluster/test_connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ async def test_send_and_receive(echo: EchoClient, connection: ConnectionInfo):
await echo.send_message(
connection,
{
"@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/trust_ping/1.0/ping",
"@type": "https://didcomm.org/trust_ping/1.0/ping",
"response_resquested": True,
},
)
response = await echo.get_message(connection)
assert response["@type"] == (
"did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/trust_ping/1.0/ping_response"
)
assert response["@type"] == ("https://didcomm.org/trust_ping/1.0/ping_response")
1 change: 0 additions & 1 deletion int/tests/cluster/test_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import json



LOGGER = logging.getLogger(__name__)


Expand Down
6 changes: 2 additions & 4 deletions int/tests/host/test_connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ async def test_send_and_receive(echo: EchoClient, connection: ConnectionInfo):
await echo.send_message(
connection,
{
"@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/trust_ping/1.0/ping",
"@type": "https://didcomm.org/trust_ping/1.0/ping",
"response_resquested": True,
},
)
response = await echo.get_message(connection)
assert response["@type"] == (
"did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/trust_ping/1.0/ping_response"
)
assert response["@type"] == ("https://didcomm.org/trust_ping/1.0/ping_response")
1 change: 0 additions & 1 deletion int/tests/host/test_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import json



LOGGER = logging.getLogger(__name__)


Expand Down
Loading