Skip to content

Address Resolver

The address resolver is a callback that intercepts host/port resolution when a GLIDE client connects to Valkey. It’s useful for DNS overrides, service mesh scenarios, or testing with fake addresses.

Pass a callable to the address resolver parameter. The callable receives the original host and port, and returns the resolved address.

from glide import GlideClient, GlideClientConfiguration, NodeAddress
real_host = "127.0.0.1"
real_port = 6379
# The resolver receives the configured host/port and returns the address to use
def resolver(host: str, port: int) -> tuple[str, int]:
return (real_host, real_port)
config = GlideClientConfiguration(
addresses=[NodeAddress("host.unreachable", 9999)],
address_resolver=resolver,
)
client = await GlideClient.create(config)
# Client is now connected to 127.0.0.1:6379
await client.set("key", "value")

If the resolver throws an exception or returns invalid data, the client falls back to the original address.

from glide import GlideClient, GlideClientConfiguration, NodeAddress
# This resolver throws — the client will use the original address.
# Returning None or an invalid value triggers the same fallback.
def resolver(host: str, port: int) -> tuple[str, int]:
raise RuntimeError("Resolution failed")
client = await GlideClient.create(
GlideClientConfiguration(
addresses=[NodeAddress("localhost", 6379)],
address_resolver=resolver,
)
)
# Still connects to localhost:6379

The cluster client supports the same resolver signature.

from glide import GlideClusterClient, GlideClusterClientConfiguration, NodeAddress
def resolver(host: str, port: int) -> tuple[str, int]:
return (get_actual_host(host), port)
client = await GlideClusterClient.create(
GlideClusterClientConfiguration(
addresses=[NodeAddress("internal-dns.service", 7000)],
address_resolver=resolver,
)
)
  • Each client instance maintains its own resolver — multiple clients can use different resolvers without interfering with each other.
  • The resolver is called synchronously during connection establishment and during cluster topology refreshes, so it must be fast and avoid blocking operations.
  • Node.js / Python / Java: If the resolver throws, the client falls back to the original address.
  • Python: Returning None or an otherwise invalid value triggers fallback to the original address. Address resolver support is provided by the async client.
  • Java: The resolver must be thread-safe.
  • Go: The resolver may be called from multiple goroutines and must be safe for concurrent use. Returning an empty host, a port outside the range 1–65535, or panicking triggers fallback to the original address.
  • PHP: Resolver state is cleared on PHP module shutdown (MSHUTDOWN) and request shutdown (RSHUTDOWN).
  • C#: The resolver delegate must be thread-safe. The maximum resolved hostname length is 1024 bytes — if exceeded, the client falls back to the original address. The delegate’s GC pin is handled internally by the client.