forked from mirror/redis
Merge pull request #644 from go-redis/fix/tx-pipeline-cmdable
Add TxPipeline to Cmdable
This commit is contained in:
commit
83513b5140
|
@ -895,7 +895,7 @@ func (c *ClusterClient) Pipeline() Pipeliner {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClusterClient) Pipelined(fn func(Pipeliner) error) ([]Cmder, error) {
|
func (c *ClusterClient) Pipelined(fn func(Pipeliner) error) ([]Cmder, error) {
|
||||||
return c.Pipeline().pipelined(fn)
|
return c.Pipeline().Pipelined(fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClusterClient) pipelineExec(cmds []Cmder) error {
|
func (c *ClusterClient) pipelineExec(cmds []Cmder) error {
|
||||||
|
@ -1033,7 +1033,7 @@ func (c *ClusterClient) TxPipeline() Pipeliner {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClusterClient) TxPipelined(fn func(Pipeliner) error) ([]Cmder, error) {
|
func (c *ClusterClient) TxPipelined(fn func(Pipeliner) error) ([]Cmder, error) {
|
||||||
return c.TxPipeline().pipelined(fn)
|
return c.TxPipeline().Pipelined(fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClusterClient) txPipelineExec(cmds []Cmder) error {
|
func (c *ClusterClient) txPipelineExec(cmds []Cmder) error {
|
||||||
|
|
|
@ -42,6 +42,9 @@ type Cmdable interface {
|
||||||
Pipeline() Pipeliner
|
Pipeline() Pipeliner
|
||||||
Pipelined(fn func(Pipeliner) error) ([]Cmder, error)
|
Pipelined(fn func(Pipeliner) error) ([]Cmder, error)
|
||||||
|
|
||||||
|
TxPipelined(fn func(Pipeliner) error) ([]Cmder, error)
|
||||||
|
TxPipeline() Pipeliner
|
||||||
|
|
||||||
ClientGetName() *StringCmd
|
ClientGetName() *StringCmd
|
||||||
Echo(message interface{}) *StringCmd
|
Echo(message interface{}) *StringCmd
|
||||||
Ping() *StatusCmd
|
Ping() *StatusCmd
|
||||||
|
|
10
pipeline.go
10
pipeline.go
|
@ -13,9 +13,7 @@ type Pipeliner interface {
|
||||||
Process(cmd Cmder) error
|
Process(cmd Cmder) error
|
||||||
Close() error
|
Close() error
|
||||||
Discard() error
|
Discard() error
|
||||||
discard() error
|
|
||||||
Exec() ([]Cmder, error)
|
Exec() ([]Cmder, error)
|
||||||
pipelined(fn func(Pipeliner) error) ([]Cmder, error)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ Pipeliner = (*Pipeline)(nil)
|
var _ Pipeliner = (*Pipeline)(nil)
|
||||||
|
@ -104,3 +102,11 @@ func (c *Pipeline) Pipelined(fn func(Pipeliner) error) ([]Cmder, error) {
|
||||||
func (c *Pipeline) Pipeline() Pipeliner {
|
func (c *Pipeline) Pipeline() Pipeliner {
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Pipeline) TxPipelined(fn func(Pipeliner) error) ([]Cmder, error) {
|
||||||
|
return c.pipelined(fn)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Pipeline) TxPipeline() Pipeliner {
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
8
redis.go
8
redis.go
|
@ -361,7 +361,7 @@ func (c *Client) PoolStats() *PoolStats {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Pipelined(fn func(Pipeliner) error) ([]Cmder, error) {
|
func (c *Client) Pipelined(fn func(Pipeliner) error) ([]Cmder, error) {
|
||||||
return c.Pipeline().pipelined(fn)
|
return c.Pipeline().Pipelined(fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Pipeline() Pipeliner {
|
func (c *Client) Pipeline() Pipeliner {
|
||||||
|
@ -373,7 +373,7 @@ func (c *Client) Pipeline() Pipeliner {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) TxPipelined(fn func(Pipeliner) error) ([]Cmder, error) {
|
func (c *Client) TxPipelined(fn func(Pipeliner) error) ([]Cmder, error) {
|
||||||
return c.TxPipeline().pipelined(fn)
|
return c.TxPipeline().Pipelined(fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TxPipeline acts like Pipeline, but wraps queued commands with MULTI/EXEC.
|
// TxPipeline acts like Pipeline, but wraps queued commands with MULTI/EXEC.
|
||||||
|
@ -425,7 +425,7 @@ type Conn struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conn) Pipelined(fn func(Pipeliner) error) ([]Cmder, error) {
|
func (c *Conn) Pipelined(fn func(Pipeliner) error) ([]Cmder, error) {
|
||||||
return c.Pipeline().pipelined(fn)
|
return c.Pipeline().Pipelined(fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conn) Pipeline() Pipeliner {
|
func (c *Conn) Pipeline() Pipeliner {
|
||||||
|
@ -437,7 +437,7 @@ func (c *Conn) Pipeline() Pipeliner {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conn) TxPipelined(fn func(Pipeliner) error) ([]Cmder, error) {
|
func (c *Conn) TxPipelined(fn func(Pipeliner) error) ([]Cmder, error) {
|
||||||
return c.TxPipeline().pipelined(fn)
|
return c.TxPipeline().Pipelined(fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TxPipeline acts like Pipeline, but wraps queued commands with MULTI/EXEC.
|
// TxPipeline acts like Pipeline, but wraps queued commands with MULTI/EXEC.
|
||||||
|
|
10
ring.go
10
ring.go
|
@ -436,7 +436,7 @@ func (c *Ring) Pipeline() Pipeliner {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Ring) Pipelined(fn func(Pipeliner) error) ([]Cmder, error) {
|
func (c *Ring) Pipelined(fn func(Pipeliner) error) ([]Cmder, error) {
|
||||||
return c.Pipeline().pipelined(fn)
|
return c.Pipeline().Pipelined(fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Ring) pipelineExec(cmds []Cmder) error {
|
func (c *Ring) pipelineExec(cmds []Cmder) error {
|
||||||
|
@ -493,3 +493,11 @@ func (c *Ring) pipelineExec(cmds []Cmder) error {
|
||||||
|
|
||||||
return firstCmdsErr(cmds)
|
return firstCmdsErr(cmds)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Ring) TxPipeline() Pipeliner {
|
||||||
|
panic("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Ring) TxPipelined(fn func(Pipeliner) error) ([]Cmder, error) {
|
||||||
|
panic("not implemented")
|
||||||
|
}
|
||||||
|
|
10
tx.go
10
tx.go
|
@ -91,5 +91,13 @@ func (c *Tx) Pipeline() Pipeliner {
|
||||||
// TxFailedErr is returned. Otherwise Exec returns error of the first
|
// TxFailedErr is returned. Otherwise Exec returns error of the first
|
||||||
// failed command or nil.
|
// failed command or nil.
|
||||||
func (c *Tx) Pipelined(fn func(Pipeliner) error) ([]Cmder, error) {
|
func (c *Tx) Pipelined(fn func(Pipeliner) error) ([]Cmder, error) {
|
||||||
return c.Pipeline().pipelined(fn)
|
return c.Pipeline().Pipelined(fn)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Tx) TxPipelined(fn func(Pipeliner) error) ([]Cmder, error) {
|
||||||
|
return c.Pipelined(fn)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Tx) TxPipeline() Pipeliner {
|
||||||
|
return c.Pipeline()
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,8 +90,8 @@ func (o *UniversalOptions) simple() *Options {
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Options{
|
return &Options{
|
||||||
Addr: addr,
|
Addr: addr,
|
||||||
DB: o.DB,
|
DB: o.DB,
|
||||||
|
|
||||||
MaxRetries: o.MaxRetries,
|
MaxRetries: o.MaxRetries,
|
||||||
Password: o.Password,
|
Password: o.Password,
|
||||||
|
@ -117,6 +117,9 @@ type UniversalClient interface {
|
||||||
Close() error
|
Close() error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var _ UniversalClient = (*Client)(nil)
|
||||||
|
var _ UniversalClient = (*ClusterClient)(nil)
|
||||||
|
|
||||||
// NewUniversalClient returns a new multi client. The type of client returned depends
|
// NewUniversalClient returns a new multi client. The type of client returned depends
|
||||||
// on the following three conditions:
|
// on the following three conditions:
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in New Issue