1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-26 19:21:03 +03:00

fix: remove mutex from pipeline

This commit is contained in:
Vladimir Mihailenco
2023-01-21 10:41:51 +02:00
parent e314cd9846
commit 6525bbbaa1
3 changed files with 6 additions and 83 deletions

View File

@ -2,7 +2,6 @@ package redis
import (
"context"
"sync"
)
type pipelineExecer func(context.Context, []Cmder) error
@ -39,8 +38,6 @@ type Pipeline struct {
statefulCmdable
exec pipelineExecer
mu sync.Mutex
cmds []Cmder
}
@ -51,10 +48,7 @@ func (c *Pipeline) init() {
// Len returns the number of queued commands.
func (c *Pipeline) Len() int {
c.mu.Lock()
ln := len(c.cmds)
c.mu.Unlock()
return ln
return len(c.cmds)
}
// Do queues the custom command for later execution.
@ -66,17 +60,13 @@ func (c *Pipeline) Do(ctx context.Context, args ...interface{}) *Cmd {
// Process queues the cmd for later execution.
func (c *Pipeline) Process(ctx context.Context, cmd Cmder) error {
c.mu.Lock()
c.cmds = append(c.cmds, cmd)
c.mu.Unlock()
return nil
}
// Discard resets the pipeline and discards queued commands.
func (c *Pipeline) Discard() {
c.mu.Lock()
c.cmds = c.cmds[:0]
c.mu.Unlock()
}
// Exec executes all previously queued commands using one
@ -85,9 +75,6 @@ func (c *Pipeline) Discard() {
// Exec always returns list of commands and error of the first failed
// command if any.
func (c *Pipeline) Exec(ctx context.Context) ([]Cmder, error) {
c.mu.Lock()
defer c.mu.Unlock()
if len(c.cmds) == 0 {
return nil, nil
}