Skip to main content
The @healthzkit/memcached package provides HealthAdapter implementations for the memcached and memjs clients. Each adapter runs a read-only check and returns ok with metadata.latencyMs, or fail with the caught error.

Install

Install the adapter and the client you use:
Both clients are optional peers. For TypeScript, also install @types/memcached or @types/memjs for your chosen client. The package requires Node.js 22.12+ and uses ESM.

Basic readiness check

Client imports

Use a subpath import for your chosen client. Both factories and their option types are also exported from @healthzkit/memcached.

memcachedAdapter

Peer: memcached >= 2.2.2. Supply either servers with optional client options, or an existing client:
The adapter runs VERSION and fails on any reported server error or an empty version response. The client uses the ASCII protocol and does not support SASL authentication.

memjsAdapter

Peer: memjs >= 1.3.2.
A cache miss is healthy because the server responded successfully. The adapter does not write or delete data, and you do not need to create the key first. The check covers the server selected for that key. It does not verify every cluster member. Your client’s failover settings also affect which server responds.

Metadata

Both adapters measure command latency before running the optional metadata hook:
A successful result includes:
Measured latencyMs takes precedence over a field with the same name from your hook. A hook error fails the check.

Client lifecycle and scheduling

When you supply servers, the adapter creates the client on its first check and reuses it across later and concurrent checks. It keeps connections open between checks. For explicit shutdown control, supply your own client. Call client.end() for memcached or client.close() for memjs when your application stops. The adapter does not close supplied clients. Use Scheduling to cache readiness results and avoid querying Memcached on every HTTP request.