mirror of
https://github.com/BerriAI/litellm.git
synced 2026-12-01 01:18:34 +00:00
redis_py_kwargs.py reads each redis-py version's signatures in a throwaway uv environment and the REDIS_* names from litellm._redis under the locked version, then writes the catalog. Run on this branch it reproduces every arg row of the hand-made file, so only the meta text changes. test_redis.py now loads the script's arg_signatures instead of keeping its own copy of the introspection, so the code that writes the file is the code that checks it in every redis-compat CI job
9.1 KiB
9.1 KiB
Interpreting merged kwargs
- The boundary is merged redis-py kwargs in,
litellm_redis_types::Resolutionout.interprettakes the dict a host already merged the way_merge_redis_kwargsinlitellm/_redis.pydoes, with itsREDIS_*values andget_secretfallbacks filled, and stands in for redis-py's constructors andfrom_url. It never reads the environment or a secret, so both hosts share it. EveryEntrykeeps the source a warning or error names, whichkwargssets to the kwarg name and the gateway merge sets toREDIS_<KWARG>or the fallback name - The
Resolutionholds the target, the auth and the timeouts Rust models, every other plain setting verbatim inpassthrough, the names of object-valued settings inhost_objects, and every setting the Rust client ignores as anIgnoredwith its source and consequence, which the host logs. A host passes itscredential_providerobject as aProviderHandle, and acredential_providerkey without one isError::ProviderWithoutHandle. Azure's username is read fromos.environby Python, sointerpretleavesAzureAdAuth::usernameunset and the host fills it in options.rsreads the kwargs into the typedOptionsand splits the unmodeled settings into passthrough and host objects and collects ignored ones.endpoint.rs,auth.rsandtls.rspick the target, the credentials and TLS fromOptionsalone- Rust never introspects redis-py. Every Redis kwarg redis-py or
litellm/_redis.pyaccepts is one row inSETTINGSinsrc/keys.rs, and that row is the whole answer for the kwarg: itsHandling(Read,Warnwith the consequence the warning names, orReject), itsShape(plain data lands inpassthrough, a Python object inhost_objects), whether a url query carries it (FromUrl), whether_get_redis_env_kwarg_mappingreads it asREDIS_<KWARG>, and the names_merge_redis_kwargsfalls back to. The last two columns are only read by the gateway merge, and they stay on the row so there is one table. AReadrow is a field ofOptions, which an inline test pins. A kwarg with no row is not a Redis setting, so it passes through without a warning redis-py-kwargs.jsonholds the Python facts each row answers: which redis-py versions name the kwarg in which signature, and whether Python reads itsREDIS_*name under the locked redis-py. Never edit it by hand.redis_py_kwargs.pynext to it regenerates it, and its docstring says how to run it. A kwarg litellm reads that no signature orREDIS_*name covers goes in itsLITELLM_ONLY, and a new redis-py version in itsVERSIONSand theredis-compatCI matrix together.test_redis_py_kwargs_catalog_matches_the_installed_redis_pyintests/unit/test_redis.pychecks it against each version theredis-compatCI matrix installs, andtests/catalog.rsfails untilSETTINGShas exactly one row per kwarg in it with the sameenvironment. A redis-py bump that adds a kwarg therefore cannot land without a row deciding how Rust handles it- The contract is
resolves_like_python_redisintests/interpret.rsand its mirrortest_redis_settings_resolve_like_the_rust_resolver_expectsintests/unit/test_redis.py. Each case holds the merged dict, the sources the merge gave it, and the expected view written next to it. The Python side asserts that_merge_redis_kwargsreturns that merged dict and reads the effective redis-py 5.3.1 connection objects without connecting, andmerges_like_python_redisingateway/src/redis/surface_tests.rspins the same merged dicts from the Rust merge. A new rule is a new case in every file, never a generated fixture. Python and Rust pods share one Redis during the switch, so a change here is a change to a wire contract - A url carries its own TLS. redis-py's url allowlist is the plain
Connectionsignature, so everyssl_*setting outside the url is dropped, and a credential provider strips the url's userinfo. Arediss://url'sssl_cert_reqs,ssl_ca_certs,ssl_ca_data,ssl_ca_path,ssl_certfile,ssl_keyfile,ssl_passwordandssl_check_hostnamequery parameters are read likeparse_urlreads them - TLS options and
dbare only read for the endpoint that uses them, so a badssl_cert_reqsnever fails a url target. A cluster with a non-zerodb, and Sentinel with ahostorport, are errors because redis-py raises building those clients - An empty value (
"",[],{}) is the same as an unset one, like Python'sx or ... - Precedence matches Python. The target is cluster, then URL, then Sentinel (
sentinel_nodesplusservice_name), then host. Auth is acredential_providerhandle, then GCP, then Azure, then AWS, and the first one wins with a warning - Numbers are read with
litellm_python_compat::number, so whitespace and digit underscores parse like Python'sint()andfloat(). A value they cannot parse (port: abc,socket_timeout: slow) is dropped with a warning and the default is used, like_coerce_redis_kwargs_types. A number that parses but is out of range (negative seconds, a port above 65535) fails withError::Invalid - Flags (
ssl,ssl_check_hostname,aws_iam_auth,aws_iam_serverless) are read one way on every surface.true,1andyesare true andfalse,0,no,off,fandnare false, the text redis-py's_str_to_booland the proxy's pydantic models agree on. Any other text isError::Invalid, so a TLS setting is never guessed - The resolver fails on a setting it cannot honor only when that setting is a security check. A
Warnrow is dropped and returned as anIgnorednaming its source (ssl_ciphersorREDIS_SSL_CIPHERS) and the consequence on its row, because a Python deployment that worked must keep working when its stores move to Rust. Only a value that is malformed (Error::Invalid), a target that is missing or aRejectrow that asks for its check fails. Promoting aWarnrow toReadis then a pure improvement with no behavior cliff, while moving one toRejectcan fail a config that connects today- A
Warnrow with ametcheck is dropped silently when its value asks for nothing more than Rust does, sossl_min_versionof TLS 1.2 or lower never warns - A
Rejectrow is a security check rustls cannot perform that Python's locked async client already refuses with aTypeError, so failing closed breaks no proxy that runs today.tests/catalog.rsfails if the locked redis-py's async, cluster or connection signature accepts aRejectrow, so a redis-py bump forces the decision again. A row'sAskedsays which values ask for the check, from the kwargs,REDIS_*or a url query, and those areError::Unenforceablessl_validate_ocspandssl_validate_ocsp_stapledask when true, because rustls has no client-side OCSP. False asks for nothing and is dropped without a warningssl_include_verify_flagsandssl_exclude_verify_flagsask when set, because rustls takes no X.509 verify flags such as CRL checking. An empty list asks for nothing
ssl_ca_dataandssl_ca_pathare read intoTlsOptionsand trusted next tossl_ca_certs.ssl_passwordis read intoTlsOptions::key_password, whichredis-clientuses to decrypt a PKCS#8 key like the sync client'sload_cert_chain(password=...). redis-py 5.3.1's async client refuses it, so this is a superset of the path the proxy uses, likessl_ca_pathunix_socket_pathresolves toTarget::Unix, which like redis-py'sUnixDomainSocketConnectionreplaces host, port and TLS. Python still requireshostnext to it, so Rust does too- A url's
?db=,?username=and?password=are read likeparse_urlreads them, so?db=wins over the path and the userinfo wins over?username=and?password=. Any other query parameter, including one with no row, is ignored namingurl ?<name>, because redis-py turns each one into a client kwarg. Which ones a url carries is theFromUrlcolumn socket_keepaliveis warned, but cluster clients still turn TCP keepalive on, like Python's async cluster defaulthealth_check_intervalis read as anintof seconds like_coerce_redis_kwargs_typesintoHealthCheck. Zero isDisabledand stays off on every target, a negative interval checks before every command like redis-py, and onlyUnsettakes a default.redis-connectgives an unset cluster Python's 25s default andredis-clientpings every node before the next command once the client sat idle that long, outside the breaker and the call events
- A
- Cases where Rust and Python disagree on purpose are cases in both contract tests with a different expected outcome on each side
ssl_ca_path: redis-py 5.3.1's asyncRedishas no such parameter and raisesTypeErrorbuilding the client, while Rust trusts the directory likeload_verify_locations(capath=...)on,tandyfor a flag areError::Invalidon every surface. pydantic reads them as true forcoordination_redisand_str_to_boolreads them as false everywhere else, so Rust refuses to pick one. Other unrecognized text is false in Python and an error here- Empty
sentinel_nodeswith noREDIS_SENTINEL_NODESis no target at all, so it fails as "either host or url must be specified". redis-py keeps the empty list and fails building the Sentinel client