mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
test(e2e): take the direct-GET spend-counter path on E2E_REDIS_CLUSTER
The gateway's cache sets no namespace, so the counter key is the bare
spend🔑<hash>. Trigger the cluster-safe direct GET on E2E_REDIS_CLUSTER (not
only on E2E_REDIS_NAMESPACE) so the cluster deploy need not set a namespace it
does not use; the namespaced key is still tried first when a namespace is given.
This commit is contained in:
parent
bd19adc1ef
commit
6e613427ad
1 changed files with 9 additions and 5 deletions
|
|
@ -61,14 +61,18 @@ def _redis():
|
|||
|
||||
def _spend_counter(rds, key: str) -> float | None:
|
||||
"""The shared spend counter for `key`, or None if it is cold. The counter key is
|
||||
``{cache namespace}:spend:key:{sha256(key)}``. With E2E_REDIS_NAMESPACE set (the
|
||||
cluster-mode deploy, where a keyspace SCAN can't span shards) read it directly;
|
||||
otherwise match by suffix so a local namespace need not be hard-coded."""
|
||||
the optional cache namespace plus ``spend:key:{sha256(key)}``. A cluster client
|
||||
can't run a keyspace SCAN that spans shards, so on E2E_REDIS_CLUSTER (or when a
|
||||
namespace is given) read the key directly - the namespaced key, then the bare
|
||||
suffix. Otherwise match by suffix so a local namespace need not be hard-coded."""
|
||||
digest = hashlib.sha256(key.encode()).hexdigest()
|
||||
suffix = f"spend:key:{digest}"
|
||||
namespace = os.getenv("E2E_REDIS_NAMESPACE")
|
||||
if namespace:
|
||||
for candidate in (f"{namespace}:{suffix}", suffix):
|
||||
cluster = os.getenv("E2E_REDIS_CLUSTER", "false").lower() in ("1", "true", "yes")
|
||||
if cluster or namespace:
|
||||
candidates = [f"{namespace}:{suffix}"] if namespace else []
|
||||
candidates.append(suffix)
|
||||
for candidate in candidates:
|
||||
raw = rds.get(candidate)
|
||||
if raw is not None:
|
||||
return float(raw)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue