-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Redis pipeline support #134
Copy link
Copy link
Open
Labels
area/driverDatabase/cache driver infrastructureDatabase/cache driver infrastructuredriver/redisRedis driverRedis driver
Milestone
Description
Summary
Implement Redis pipelining — batching multiple commands into a single write and collecting responses in order. This dramatically reduces round-trip overhead for bulk operations.
Design
Package: driver/redis/pipeline.go
API
type Pipeline struct {
client *Client
commands []pipelineCmd
}
type pipelineCmd struct {
args []string
doneCh chan Value
}
func (c *Client) Pipeline() *Pipeline
func (p *Pipeline) Get(key string) *StringCmd
func (p *Pipeline) Set(key string, value any, exp time.Duration) *StatusCmd
func (p *Pipeline) Del(keys ...string) *IntCmd
func (p *Pipeline) Incr(key string) *IntCmd
// ... all command methods mirror Client but return deferred result types
func (p *Pipeline) Exec(ctx context.Context) ([]Cmd, error)Deferred Result Types
type StringCmd struct {
val string
err error
}
func (c *StringCmd) Result() (string, error)
type IntCmd struct {
val int64
err error
}
func (c *IntCmd) Result() (int64, error)
type StatusCmd struct {
val string
err error
}
func (c *StatusCmd) Result() (string, error)Execution Flow
- User calls pipeline methods — commands are buffered, not sent
Exec(ctx)serializes ALL commands into a single byte buffer- Writes entire buffer in one event loop write
- Creates N
doneChchannels (one per command) - Event loop receives responses — FIFO order matches command order
- Each response dispatched to corresponding
doneCh Execcollects all results, returns
Automatic Pipelining (optional)
For advanced use, automatic pipelining collects commands from multiple goroutines within a time window:
func WithAutoPipeline(window time.Duration) OptionCommands arriving within the window are batched automatically. This is an optimization for high-concurrency scenarios.
Acceptance Criteria
- Pipeline API with all major command methods
-
Execbatches commands into single write - Responses correctly matched to commands (FIFO)
- Deferred result types with type-safe
Result()methods - Error in one command doesn't affect others
- Context cancellation during
Exec - Benchmark: pipelined vs non-pipelined throughput
- Unit tests with 100+ commands in single pipeline
Dependencies
- Depends on 133 (Redis client API + RedisState)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area/driverDatabase/cache driver infrastructureDatabase/cache driver infrastructuredriver/redisRedis driverRedis driver