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

This commit is contained in:
Masen Furer 2024-05-31 14:58:25 -07:00 committed by GitHub
parent 16fc3936a4
commit 5995b32f5f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -7,6 +7,7 @@ import contextlib
import copy import copy
import functools import functools
import inspect import inspect
import os
import traceback import traceback
import uuid import uuid
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
@ -35,6 +36,7 @@ except ModuleNotFoundError:
import wrapt import wrapt
from redis.asyncio import Redis from redis.asyncio import Redis
from redis.exceptions import ResponseError
from reflex import constants from reflex import constants
from reflex.base import Base from reflex.base import Base
@ -2638,13 +2640,26 @@ class StateManagerRedis(StateManager):
Args: Args:
lock_key: The redis key for the lock. lock_key: The redis key for the lock.
lock_id: The ID of the lock. lock_id: The ID of the lock.
Raises:
ResponseError: when the keyspace config cannot be set.
""" """
state_is_locked = False state_is_locked = False
lock_key_channel = f"__keyspace@0__:{lock_key.decode()}" lock_key_channel = f"__keyspace@0__:{lock_key.decode()}"
# Enable keyspace notifications for the lock key, so we know when it is available. # Enable keyspace notifications for the lock key, so we know when it is available.
await self.redis.config_set( try:
"notify-keyspace-events", self._redis_notify_keyspace_events 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: async with self.redis.pubsub() as pubsub:
await pubsub.psubscribe(lock_key_channel) await pubsub.psubscribe(lock_key_channel)
while not state_is_locked: while not state_is_locked: