Merge pull request #90 from kortix-ai/redis

Redis
This commit is contained in:
Dat LQ. 2025-04-24 01:46:35 +01:00 committed by GitHub
commit be39b91a96
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 577 additions and 686 deletions

File diff suppressed because it is too large Load Diff

View File

@ -8,6 +8,7 @@ from utils.logger import logger
from utils.config import config
import random
from functools import wraps
from typing import List # Added for type hinting
# Redis client
client = None
@ -77,11 +78,11 @@ def initialize():
ssl=config.REDIS_SSL,
ssl_ca_certs=certifi.where(),
decode_responses=True,
socket_timeout=5.0, # Socket timeout
socket_timeout=5.0,
socket_connect_timeout=5.0, # Connection timeout
retry_on_timeout=True, # Auto-retry on timeout
health_check_interval=30, # Check connection health every 30 seconds
max_connections=10 # Limit connections to prevent overloading
max_connections=200 # Limit connections to prevent overloading
)
return client
@ -168,7 +169,31 @@ async def keys(pattern):
redis_client = await get_client()
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():
"""Create a Redis pubsub object."""
redis_client = await get_client()
# decode_responses=True in client init applies to pubsub messages too
return redis_client.pubsub()

View File

@ -579,7 +579,7 @@ export default function ThreadPage({ params }: { params: Promise<ThreadParams> }
};
}, [threadId]);
const handleSubmitMessage = useCallback(async (message: string) => {
const handleSubmitMessage = useCallback(async (message: string, options?: { model_name?: string; enable_thinking?: boolean }) => {
if (!message.trim()) return;
setIsSending(true);
@ -601,7 +601,7 @@ export default function ThreadPage({ params }: { params: Promise<ThreadParams> }
try {
const results = await Promise.allSettled([
addUserMessage(threadId, message),
startAgent(threadId)
startAgent(threadId, options)
]);
if (results[0].status === 'rejected') {