Add TxPipeline to Cmdable

This commit is contained in:
Vladimir Mihailenco 2017-09-25 11:48:44 +03:00
parent 975882d73d
commit f9307ab2fe
7 changed files with 40 additions and 12 deletions

View File

@ -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 {

View File

@ -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

View File

@ -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
}

View File

@ -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
View File

@ -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
View File

@ -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()
} }

View File

@ -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:
// //