Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REF-2978] Ignore Redis config_set for AWS ElastiCache #3401

Merged
merged 2 commits into from
May 31, 2024
Merged
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
21 changes: 18 additions & 3 deletions reflex/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import copy
import functools
import inspect
import os
import traceback
import uuid
from abc import ABC, abstractmethod
Expand Down Expand Up @@ -35,6 +36,7 @@

import wrapt
from redis.asyncio import Redis
from redis.exceptions import ResponseError

from reflex import constants
from reflex.base import Base
Expand Down Expand Up @@ -2638,13 +2640,26 @@ async def _wait_lock(self, lock_key: bytes, lock_id: bytes) -> None:
Args:
lock_key: The redis key for the lock.
lock_id: The ID of the lock.

Raises:
ResponseError: when the keyspace config cannot be set.
"""
state_is_locked = False
lock_key_channel = f"__keyspace@0__:{lock_key.decode()}"
# Enable keyspace notifications for the lock key, so we know when it is available.
await self.redis.config_set(
"notify-keyspace-events", self._redis_notify_keyspace_events
)
try:
await self.redis.config_set(
"notify-keyspace-events",
self._redis_notify_keyspace_events,
)
except ResponseError:
# Some redis servers only allow out-of-band configuration, so ignore errors here.
ignore_config_error = os.environ.get(
"REFLEX_IGNORE_REDIS_CONFIG_ERROR",
None,
)
if not ignore_config_error:
raise
async with self.redis.pubsub() as pubsub:
await pubsub.psubscribe(lock_key_channel)
while not state_is_locked:
Expand Down
Loading