mirror of
https://github.com/redis/go-redis.git
synced 2026-10-24 07:59:20 +03:00
* chore(deps): bump golang.org/x/sys from 0.48.0 to 0.49.0 Bumps [golang.org/x/sys](https://github.com/golang/sys) from 0.48.0 to 0.49.0. - [Commits](https://github.com/golang/sys/compare/v0.48.0...v0.49.0) --- updated-dependencies: - dependency-name: golang.org/x/sys dependency-version: 0.49.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * chore(deps): go mod tidy submodules for x/sys 0.49.0 Example and extra modules still pinned x/sys v0.48.0, so govulncheck failed with "go mod tidy" in each of them. --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Nedyalko Dyakov <nedyalko.dyakov@gmail.com>
Client-side caching example
This example enables the built-in client-side cache on a standalone go-redis client. It demonstrates:
- a first read fetched from Redis
- a repeated read served from the local cache
- automatic eviction after another client changes the key
- cache hit and miss statistics through
CSCStats
go-redis uses Redis CLIENT TRACKING and RESP3 invalidation notifications to
keep the local cache synchronized. Invalidations are asynchronous, so the
example waits until the cached client observes the updated value.
Requirements
- Redis with
CLIENT TRACKINGsupport - RESP3
- database 0
- no dynamic credential provider
Fixed Username and Password values are supported.
Run
The Redis address defaults to localhost:6379. Override it with REDIS_ADDR:
go run .
# or
REDIS_ADDR=localhost:6390 go run .
Expected output:
first read: hello
second read: hello
cache stats: 1 hit, 1 miss
after invalidation: hello again