mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-25 22:20:43 +00:00
Reworks the redis-client, connect, resolve and testing crates, adds python-compat json loads and TTL seconds, replaces the redis-store memory tier with a DualCache plus a shared failure log, and gives the Python side the Redis timeout log throttle and a request OTEL parent span for service events Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
import asyncio
|
|
from typing import Final
|
|
|
|
import pytest
|
|
from redis.credentials import CredentialProvider
|
|
|
|
from litellm.rust_bridge.host.redis_credentials import credentials
|
|
|
|
|
|
class _SyncOnly(CredentialProvider):
|
|
def __init__(self, answer: tuple[str] | tuple[str, str]) -> None:
|
|
self.answer: Final = answer
|
|
|
|
def get_credentials(self) -> tuple[str] | tuple[str, str]:
|
|
return self.answer
|
|
|
|
|
|
class _AsyncOnly(CredentialProvider):
|
|
def get_credentials(self) -> tuple[str, str]:
|
|
raise AssertionError("redis-py's async connection asks get_credentials_async")
|
|
|
|
async def get_credentials_async(self) -> tuple[str, str]:
|
|
await asyncio.sleep(0)
|
|
return "async-user", "async-password"
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("provider", "expected"),
|
|
[
|
|
(_SyncOnly(("token",)), (None, "token")),
|
|
(_SyncOnly(("user", "password")), ("user", "password")),
|
|
(_AsyncOnly(), ("async-user", "async-password")),
|
|
],
|
|
)
|
|
def test_credentials_are_what_redis_py_would_authenticate_with(
|
|
provider: CredentialProvider, expected: tuple[str | None, str]
|
|
) -> None:
|
|
assert credentials(provider) == expected
|