3 Star 0 Fork 0

Gitee 极速下载/go-redis-redissource

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/go-redis/redis
克隆/下载
pipeline.go 1.44 KB
一键复制 编辑 原始数据 按行查看 历史
Vladimir Mihailenco 提交于 2014-07-04 15:19 . More benchmarks.
package redis
// Not thread-safe.
type Pipeline struct {
*Client
closed bool
}
func (c *Client) Pipeline() *Pipeline {
return &Pipeline{
Client: &Client{
baseClient: &baseClient{
opt: c.opt,
connPool: c.connPool,
cmds: make([]Cmder, 0),
},
},
}
}
func (c *Client) Pipelined(f func(*Pipeline) error) ([]Cmder, error) {
pc := c.Pipeline()
if err := f(pc); err != nil {
return nil, err
}
cmds, err := pc.Exec()
pc.Close()
return cmds, err
}
func (c *Pipeline) Close() error {
c.closed = true
return nil
}
func (c *Pipeline) Discard() error {
if c.closed {
return errClosed
}
c.cmds = c.cmds[:0]
return nil
}
// Exec always returns list of commands and error of the first failed
// command if any.
func (c *Pipeline) Exec() ([]Cmder, error) {
if c.closed {
return nil, errClosed
}
cmds := c.cmds
c.cmds = make([]Cmder, 0)
if len(cmds) == 0 {
return []Cmder{}, nil
}
cn, err := c.conn()
if err != nil {
setCmdsErr(cmds, err)
return cmds, err
}
if err := c.execCmds(cn, cmds); err != nil {
c.freeConn(cn, err)
return cmds, err
}
c.putConn(cn)
return cmds, nil
}
func (c *Pipeline) execCmds(cn *conn, cmds []Cmder) error {
if err := c.writeCmd(cn, cmds...); err != nil {
setCmdsErr(cmds, err)
return err
}
var firstCmdErr error
for _, cmd := range cmds {
if err := cmd.parseReply(cn.rd); err != nil {
if firstCmdErr == nil {
firstCmdErr = err
}
}
}
return firstCmdErr
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors/redissource.git
git@gitee.com:mirrors/redissource.git
mirrors
redissource
go-redis-redissource
v2.3.1

搜索帮助

0d507c66 1850385 C8b1a773 1850385