feature: Valkey cache integration#1263
Open
daric93 wants to merge 17 commits intogorse-io:masterfrom
Open
Conversation
Implement Valkey as a first-class cache store backend using valkey-glide Go client. This enables Gorse users to use Valkey as an alternative to Redis for the cache layer. Changes: - Add valkey://, valkeys://, valkey+cluster://, valkeys+cluster:// URL prefix constants and config validation - Implement full cache.Database interface in storage/cache/valkey.go using valkey-glide v2 client (standalone + cluster modes) - Time series implemented via Sorted Set + Hash with Go-side bucket aggregation (no TimeSeries module dependency) - Score/document operations use valkey-search FT.* commands via CustomCommand - Add integration test suite embedding baseTestSuite - Add integration report with analysis and task breakdown Signed-off-by: Daria Korenieva <daric2612@gmail.com>
Add valkey/valkey-bundle:unstable (valkey-search 1.2.0+ with full-text search support) to storage/docker-compose.yml on port 6380. Update default test URI to valkey://127.0.0.1:6380/. Signed-off-by: Daria Korenieva <daric2612@gmail.com>
…/gorse-io-gorse into feature/valkey-cache-integration
Signed-off-by: Daria Korenieva <daric2612@gmail.com>
Signed-off-by: Daria Korenieva <daric2612@gmail.com>
…er ops, handle username in URL Signed-off-by: Daria Korenieva <daric2612@gmail.com>
…ix TAG escaping: new escapeTag() covers all special chars (| * { } etc.) to prevent query injection via user-controlled values - Fix CROSSSLOT error: delete keys one-at-a-time in cluster mode via vDel() - Fix race condition: remove non-atomic Exists+HSet in UpdateScores - Add max iteration guard (100) to DeleteScores loop - Extract wrapper methods (vDel, vHSet, vZAdd, vHGetAll) to reduce cluster/standalone branching duplication - Extract groupTimeSeriesPoints() helper to DRY AddTimeSeriesPoints
Signed-off-by: Daria Korenieva <daric2612@gmail.com>
…/gorse-io-gorse into feature/valkey-cache-integration # Conflicts: # storage/cache/valkey.go
…s - Add valkey/valkey-bundle:unstable service on port 6380 to unit_test job - Add VALKEY_URI env var for Linux unit tests - Add TestValkey to -skip pattern for macOS and Windows jobs (no Valkey service available on those runners) Signed-off-by: Daria Korenieva <daric2612@gmail.com>
…glide requires CGO (Rust FFI core) and cannot build with CGO_ENABLED=0, which gorse uses for static Docker binaries. This is a confirmed upstream limitation (valkey-io/valkey-glide#4253). valkey-go is the official pure-Go Valkey client from the same org. It supports all needed commands (FT.SEARCH, HSET, ZADD, SCAN, etc.), works with CGO_ENABLED=0, and simplifies the code by using a single Client interface for both standalone and cluster modes. Changes: - Replace valkey-glide/go/v2 with valkey-io/valkey-go in go.mod - Rewrite storage/cache/valkey.go using valkey-go command builder API - Eliminate all if-isCluster branching (valkey-go handles routing) - Use DoMulti for pipeline batching instead of standalone batch - Update tests to use valkey-go client for FLUSHDB - Update URL parsers to return plain strings instead of glide types Signed-off-by: Daria Korenieva <daric2612@gmail.com>
…/gorse-io-gorse into feature/valkey-cache-integration
… offset in SearchScores, clarify UpdateScores pagination - Set(): use DoMulti to pipeline all SET commands in a single round-trip - AddScores(): use DoMulti to pipeline all HSET commands - SearchScores(): pass begin as LIMIT offset and (end-begin) as count instead of fetching from 0 and slicing in Go - UpdateScores(): add clarifying comments for the first-page re-fetch optimization that avoids pagination drift Signed-off-by: Daria Korenieva <daric2612@gmail.com>
zhenghaoz
requested changes
May 7, 2026
Collaborator
zhenghaoz
left a comment
There was a problem hiding this comment.
Too many duplicate codes comparing to Redis backend. Please fix all tests. Could you reuse Redis client, but implement special timeseries interface if Valkey is detected?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes: #1260
Adds Valkey as a cache storage backend using the valkey-go client. Supports both standalone and cluster modes with TLS.
What's included
Databaseinterface implementation instorage/cache/valkey.go— scores (documents), time series, key-value, and queue operationsvalkey://,valkeys://,valkey+cluster://,valkeys+cluster://valkey/valkey-bundle:unstable(includes valkey-search)Design decisions
valkey-go(official Valkey client) rather than a Redis client for forward compatibilityescapeTag()function escapes all TAG special characters to prevent query injectionvDel,vHSet,vZAdd,vHGetAll) centralize cluster/standalone branchingDeleteScoresloop has a max iteration guard (100) to prevent infinite loopsUpdateScoresskips the non-atomicExistscheck — HSet directly on keys found via FT.SEARCHWhy valkey-go over valkey-glide
The initial implementation used valkey-glide, but it requires CGo — it wraps a Rust core library via FFI. Gorse builds all default Docker images and release binaries with
CGO_ENABLED=0to produce fully static binaries that run in minimalFROM scratchcontainers (see everyDockerfileandbuild_release.yml). Enabling CGo would require a C toolchain in the build environment, a libc at runtime, break theFROM scratchpattern, increase image sizes, and complicate multi-arch cross-compilation.valkey-go is a pure Go client with no CGo dependency, so it works with
CGO_ENABLED=0out of the box.Testing
baseTestSuite(TestDocument, TestPurge, TestTimeSeries, TestScanScores, etc.)Changed files
storage/cache/valkey.gostorage/cache/valkey_test.gostorage/scheme.gostorage/docker-compose.ymlconfig/config.goconfig/config.tomlconfig/config_test.gostorage/cache/database_test.gogo.mod/go.sum