mirror of https://github.com/kortix-ai/suna.git
vibe redisssss
This commit is contained in:
parent
eda0cee931
commit
008c96b153
1230
backend/agent/api.py
1230
backend/agent/api.py
File diff suppressed because it is too large
Load Diff
|
@ -7,6 +7,7 @@ import ssl
|
||||||
from utils.logger import logger
|
from utils.logger import logger
|
||||||
import random
|
import random
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
from typing import List # Added for type hinting
|
||||||
|
|
||||||
# Redis client
|
# Redis client
|
||||||
client = None
|
client = None
|
||||||
|
@ -76,11 +77,11 @@ def initialize():
|
||||||
ssl=os.getenv('REDIS_SSL', 'True').lower() == 'true',
|
ssl=os.getenv('REDIS_SSL', 'True').lower() == 'true',
|
||||||
ssl_ca_certs=certifi.where(),
|
ssl_ca_certs=certifi.where(),
|
||||||
decode_responses=True,
|
decode_responses=True,
|
||||||
socket_timeout=5.0, # Socket timeout
|
socket_timeout=None, # Changed from 5.0 to None to let listen() block indefinitely
|
||||||
socket_connect_timeout=5.0, # Connection timeout
|
socket_connect_timeout=5.0, # Connection timeout
|
||||||
retry_on_timeout=True, # Auto-retry on timeout
|
retry_on_timeout=True, # Auto-retry on timeout
|
||||||
health_check_interval=30, # Check connection health every 30 seconds
|
health_check_interval=30, # Check connection health every 30 seconds
|
||||||
max_connections=10 # Limit connections to prevent overloading
|
max_connections=1000 # Limit connections to prevent overloading
|
||||||
)
|
)
|
||||||
|
|
||||||
return client
|
return client
|
||||||
|
@ -167,7 +168,31 @@ async def keys(pattern):
|
||||||
redis_client = await get_client()
|
redis_client = await get_client()
|
||||||
return await with_retry(redis_client.keys, pattern)
|
return await with_retry(redis_client.keys, pattern)
|
||||||
|
|
||||||
|
async def rpush(key, *values):
|
||||||
|
"""Append one or more values to a list with automatic retry."""
|
||||||
|
redis_client = await get_client()
|
||||||
|
return await with_retry(redis_client.rpush, key, *values)
|
||||||
|
|
||||||
|
async def lrange(key, start, end):
|
||||||
|
"""Get a range of elements from a list with automatic retry."""
|
||||||
|
redis_client = await get_client()
|
||||||
|
# Note: lrange returns bytes if decode_responses=False, but we set it to True
|
||||||
|
# Ensure the return type is List[str]
|
||||||
|
result: List[str] = await with_retry(redis_client.lrange, key, start, end)
|
||||||
|
return result
|
||||||
|
|
||||||
|
async def llen(key):
|
||||||
|
"""Get the length of a list with automatic retry."""
|
||||||
|
redis_client = await get_client()
|
||||||
|
return await with_retry(redis_client.llen, key)
|
||||||
|
|
||||||
|
async def expire(key, time):
|
||||||
|
"""Set a key's time to live in seconds with automatic retry."""
|
||||||
|
redis_client = await get_client()
|
||||||
|
return await with_retry(redis_client.expire, key, time)
|
||||||
|
|
||||||
async def create_pubsub():
|
async def create_pubsub():
|
||||||
"""Create a Redis pubsub object."""
|
"""Create a Redis pubsub object."""
|
||||||
redis_client = await get_client()
|
redis_client = await get_client()
|
||||||
|
# decode_responses=True in client init applies to pubsub messages too
|
||||||
return redis_client.pubsub()
|
return redis_client.pubsub()
|
Loading…
Reference in New Issue