Revert "Vendor update"

This reverts commit e5f062ee91.
This commit is contained in:
Morgan Bazalgette 2017-07-25 15:09:02 +02:00
parent e5f062ee91
commit 2535a03c5f
No known key found for this signature in database
GPG Key ID: 40D328300D245DA5
23 changed files with 226 additions and 380 deletions

View File

@ -9,7 +9,7 @@ type OsuBool bool
// UnmarshalJSON converts `"0"` to false and `"1"` to true.
func (o *OsuBool) UnmarshalJSON(data []byte) error {
if string(data) == `0` {
if string(data) == `"0"` {
*o = false
return nil
}

1
vendor/gopkg.in/redis.v5/Makefile generated vendored
View File

@ -15,5 +15,4 @@ testdata/redis:
wget -qO- https://github.com/antirez/redis/archive/unstable.tar.gz | tar xvz --strip-components=1 -C $@
testdata/redis/src/redis-server: testdata/redis
sed -i 's/libjemalloc.a/libjemalloc.a -lrt/g' $</src/Makefile
cd $< && make all

77
vendor/gopkg.in/redis.v5/cluster.go generated vendored
View File

@ -14,7 +14,6 @@ import (
)
var errClusterNoNodes = internal.RedisError("redis: cluster has no nodes")
var errNilClusterState = internal.RedisError("redis: cannot load cluster slots")
// ClusterOptions are used to configure a cluster client and should be
// passed to NewClusterClient.
@ -356,14 +355,7 @@ func NewClusterClient(opt *ClusterOptions) *ClusterClient {
_, _ = c.nodes.Get(addr)
}
// Preload cluster slots.
for i := 0; i < 10; i++ {
state, err := c.reloadSlots()
if err == nil {
c._state.Store(state)
break
}
}
c.reloadSlots()
if opt.IdleCheckFrequency > 0 {
go c.reaper(opt.IdleCheckFrequency)
@ -374,11 +366,10 @@ func NewClusterClient(opt *ClusterOptions) *ClusterClient {
func (c *ClusterClient) state() *clusterState {
v := c._state.Load()
if v != nil {
return v.(*clusterState)
}
c.lazyReloadSlots()
if v == nil {
return nil
}
return v.(*clusterState)
}
func (c *ClusterClient) cmdSlotAndNode(state *clusterState, cmd Cmder) (int, *clusterNode, error) {
@ -406,12 +397,10 @@ func (c *ClusterClient) cmdSlotAndNode(state *clusterState, cmd Cmder) (int, *cl
}
func (c *ClusterClient) Watch(fn func(*Tx) error, keys ...string) error {
state := c.state()
var node *clusterNode
var err error
if state != nil && len(keys) > 0 {
node, err = state.slotMasterNode(hashtag.Slot(keys[0]))
if len(keys) > 0 {
node, err = c.state().slotMasterNode(hashtag.Slot(keys[0]))
} else {
node, err = c.nodes.Random()
}
@ -474,9 +463,8 @@ func (c *ClusterClient) Process(cmd Cmder) error {
var addr string
moved, ask, addr = internal.IsMovedError(err)
if moved || ask {
state := c.state()
if state != nil && slot >= 0 {
master, _ := state.slotMasterNode(slot)
if slot >= 0 {
master, _ := c.state().slotMasterNode(slot)
if moved && (master == nil || master.Client.getAddr() != addr) {
c.lazyReloadSlots()
}
@ -535,7 +523,7 @@ func (c *ClusterClient) ForEachNode(fn func(client *Client) error) error {
func (c *ClusterClient) ForEachMaster(fn func(client *Client) error) error {
state := c.state()
if state == nil {
return errNilClusterState
return nil
}
var wg sync.WaitGroup
@ -576,13 +564,12 @@ func (c *ClusterClient) ForEachMaster(fn func(client *Client) error) error {
// PoolStats returns accumulated connection pool stats.
func (c *ClusterClient) PoolStats() *PoolStats {
var acc PoolStats
nodes, err := c.nodes.All()
if err != nil {
return &acc
return nil
}
var acc PoolStats
for _, node := range nodes {
s := node.Client.connPool.Stats()
acc.Requests += s.Requests
@ -598,46 +585,37 @@ func (c *ClusterClient) lazyReloadSlots() {
if !atomic.CompareAndSwapUint32(&c.reloading, 0, 1) {
return
}
go func() {
for i := 0; i < 1000; i++ {
state, err := c.reloadSlots()
if err == pool.ErrClosed {
break
}
if err == nil {
c._state.Store(state)
break
}
time.Sleep(time.Millisecond)
}
time.Sleep(3 * time.Second)
c.reloadSlots()
atomic.StoreUint32(&c.reloading, 0)
}()
}
func (c *ClusterClient) reloadSlots() (*clusterState, error) {
func (c *ClusterClient) reloadSlots() {
for i := 0; i < 10; i++ {
node, err := c.nodes.Random()
if err != nil {
return nil, err
return
}
// TODO: fix race
if c.cmds == nil {
cmds, err := node.Client.Command().Result()
if err != nil {
return nil, err
}
if err == nil {
c.cmds = cmds
}
}
slots, err := node.Client.ClusterSlots().Result()
if err != nil {
return nil, err
continue
}
return newClusterState(c.nodes, slots)
state, err := newClusterState(c.nodes, slots)
if err != nil {
return
}
c._state.Store(state)
}
}
// reaper closes idle connections to the cluster.
@ -811,13 +789,8 @@ func (c *ClusterClient) txPipelineExec(cmds []Cmder) error {
return err
}
state := c.state()
if state == nil {
return errNilClusterState
}
for slot, cmds := range cmdsMap {
node, err := state.slotMasterNode(slot)
node, err := c.state().slotMasterNode(slot)
if err != nil {
setCmdsErr(cmds, err)
continue

View File

@ -58,7 +58,7 @@ func writeCmd(cn *pool.Conn, cmds ...Cmder) error {
}
}
_, err := cn.Write(cn.Wb.Bytes())
_, err := cn.NetConn.Write(cn.Wb.Bytes())
return err
}
@ -445,7 +445,7 @@ func (cmd *StringCmd) Result() (string, error) {
}
func (cmd *StringCmd) Bytes() ([]byte, error) {
return cmd.val, cmd.err
return []byte(cmd.val), cmd.err
}
func (cmd *StringCmd) Int64() (int64, error) {
@ -542,10 +542,6 @@ func (cmd *StringSliceCmd) String() string {
return cmdString(cmd, cmd.val)
}
func (cmd *StringSliceCmd) ScanSlice(container interface{}) error {
return proto.ScanSlice(cmd.Val(), container)
}
func (cmd *StringSliceCmd) readReply(cn *pool.Conn) error {
var v interface{}
v, cmd.err = cn.Rd.ReadArrayReply(stringSliceParser)

64
vendor/gopkg.in/redis.v5/commands.go generated vendored
View File

@ -50,16 +50,14 @@ type Cmdable interface {
Unlink(keys ...string) *IntCmd
Dump(key string) *StringCmd
Exists(key string) *BoolCmd
// TODO: merge with Exists in v6
ExistsMulti(keys ...string) *IntCmd
Expire(key string, expiration time.Duration) *BoolCmd
ExpireAt(key string, tm time.Time) *BoolCmd
Keys(pattern string) *StringSliceCmd
Migrate(host, port, key string, db int64, timeout time.Duration) *StatusCmd
Move(key string, db int64) *BoolCmd
ObjectRefCount(key string) *IntCmd
ObjectEncoding(key string) *StringCmd
ObjectIdleTime(key string) *DurationCmd
ObjectRefCount(keys ...string) *IntCmd
ObjectEncoding(keys ...string) *StringCmd
ObjectIdleTime(keys ...string) *DurationCmd
Persist(key string) *BoolCmd
PExpire(key string, expiration time.Duration) *BoolCmd
PExpireAt(key string, tm time.Time) *BoolCmd
@ -172,7 +170,6 @@ type Cmdable interface {
ZRem(key string, members ...interface{}) *IntCmd
ZRemRangeByRank(key string, start, stop int64) *IntCmd
ZRemRangeByScore(key, min, max string) *IntCmd
ZRemRangeByLex(key, min, max string) *IntCmd
ZRevRange(key string, start, stop int64) *StringSliceCmd
ZRevRangeWithScores(key string, start, stop int64) *ZSliceCmd
ZRevRangeByScore(key string, opt ZRangeBy) *StringSliceCmd
@ -273,13 +270,6 @@ func (c *cmdable) Ping() *StatusCmd {
return cmd
}
func (c *cmdable) Wait(numSlaves int, timeout time.Duration) *IntCmd {
cmd := NewIntCmd("wait", numSlaves, int(timeout/time.Millisecond))
c.process(cmd)
return cmd
}
func (c *cmdable) Quit() *StatusCmd {
panic("not implemented")
}
@ -326,17 +316,6 @@ func (c *cmdable) Exists(key string) *BoolCmd {
return cmd
}
func (c *cmdable) ExistsMulti(keys ...string) *IntCmd {
args := make([]interface{}, 1+len(keys))
args[0] = "exists"
for i, key := range keys {
args[1+i] = key
}
cmd := NewIntCmd(args...)
c.process(cmd)
return cmd
}
func (c *cmdable) Expire(key string, expiration time.Duration) *BoolCmd {
cmd := NewBoolCmd("expire", key, formatSec(expiration))
c.process(cmd)
@ -375,20 +354,38 @@ func (c *cmdable) Move(key string, db int64) *BoolCmd {
return cmd
}
func (c *cmdable) ObjectRefCount(key string) *IntCmd {
cmd := NewIntCmd("object", "refcount", key)
func (c *cmdable) ObjectRefCount(keys ...string) *IntCmd {
args := make([]interface{}, 2+len(keys))
args[0] = "object"
args[1] = "refcount"
for i, key := range keys {
args[2+i] = key
}
cmd := NewIntCmd(args...)
c.process(cmd)
return cmd
}
func (c *cmdable) ObjectEncoding(key string) *StringCmd {
cmd := NewStringCmd("object", "encoding", key)
func (c *cmdable) ObjectEncoding(keys ...string) *StringCmd {
args := make([]interface{}, 2+len(keys))
args[0] = "object"
args[1] = "encoding"
for i, key := range keys {
args[2+i] = key
}
cmd := NewStringCmd(args...)
c.process(cmd)
return cmd
}
func (c *cmdable) ObjectIdleTime(key string) *DurationCmd {
cmd := NewDurationCmd(time.Second, "object", "idletime", key)
func (c *cmdable) ObjectIdleTime(keys ...string) *DurationCmd {
args := make([]interface{}, 2+len(keys))
args[0] = "object"
args[1] = "idletime"
for i, key := range keys {
args[2+i] = key
}
cmd := NewDurationCmd(time.Second, args...)
c.process(cmd)
return cmd
}
@ -734,7 +731,6 @@ func (c *cmdable) MSetNX(pairs ...interface{}) *BoolCmd {
// Redis `SET key value [expiration]` command.
//
// Use expiration for `SETEX`-like behavior.
// Zero expiration means the key has no expiration time.
func (c *cmdable) Set(key string, value interface{}, expiration time.Duration) *StatusCmd {
args := make([]interface{}, 3, 4)
@ -1472,12 +1468,6 @@ func (c *cmdable) ZRemRangeByScore(key, min, max string) *IntCmd {
return cmd
}
func (c *cmdable) ZRemRangeByLex(key, min, max string) *IntCmd {
cmd := NewIntCmd("zremrangebylex", key, min, max)
c.process(cmd)
return cmd
}
func (c *cmdable) ZRevRange(key string, start, stop int64) *StringSliceCmd {
cmd := NewStringSliceCmd("zrevrange", key, start, stop)
c.process(cmd)

View File

@ -2,77 +2,56 @@ package pool
import (
"net"
"sync/atomic"
"time"
"gopkg.in/redis.v5/internal/proto"
)
const defaultBufSize = 4096
var noDeadline = time.Time{}
type Conn struct {
netConn net.Conn
NetConn net.Conn
Rd *proto.Reader
Wb *proto.WriteBuffer
Inited bool
usedAt atomic.Value
UsedAt time.Time
}
func NewConn(netConn net.Conn) *Conn {
cn := &Conn{
netConn: netConn,
NetConn: netConn,
Wb: proto.NewWriteBuffer(),
UsedAt: time.Now(),
}
cn.Rd = proto.NewReader(cn.netConn)
cn.SetUsedAt(time.Now())
cn.Rd = proto.NewReader(cn.NetConn)
return cn
}
func (cn *Conn) UsedAt() time.Time {
return cn.usedAt.Load().(time.Time)
}
func (cn *Conn) SetUsedAt(tm time.Time) {
cn.usedAt.Store(tm)
}
func (cn *Conn) SetNetConn(netConn net.Conn) {
cn.netConn = netConn
cn.Rd.Reset(netConn)
}
func (cn *Conn) IsStale(timeout time.Duration) bool {
return timeout > 0 && time.Since(cn.UsedAt()) > timeout
return timeout > 0 && time.Since(cn.UsedAt) > timeout
}
func (cn *Conn) SetReadTimeout(timeout time.Duration) error {
now := time.Now()
cn.SetUsedAt(now)
cn.UsedAt = time.Now()
if timeout > 0 {
return cn.netConn.SetReadDeadline(now.Add(timeout))
return cn.NetConn.SetReadDeadline(cn.UsedAt.Add(timeout))
}
return cn.netConn.SetReadDeadline(noDeadline)
return cn.NetConn.SetReadDeadline(noDeadline)
}
func (cn *Conn) SetWriteTimeout(timeout time.Duration) error {
now := time.Now()
cn.SetUsedAt(now)
cn.UsedAt = time.Now()
if timeout > 0 {
return cn.netConn.SetWriteDeadline(now.Add(timeout))
return cn.NetConn.SetWriteDeadline(cn.UsedAt.Add(timeout))
}
return cn.netConn.SetWriteDeadline(noDeadline)
}
func (cn *Conn) Write(b []byte) (int, error) {
return cn.netConn.Write(b)
}
func (cn *Conn) RemoteAddr() net.Addr {
return cn.netConn.RemoteAddr()
return cn.NetConn.SetWriteDeadline(noDeadline)
}
func (cn *Conn) Close() error {
return cn.netConn.Close()
return cn.NetConn.Close()
}

View File

@ -19,9 +19,7 @@ var (
var timers = sync.Pool{
New: func() interface{} {
t := time.NewTimer(time.Hour)
t.Stop()
return t
return time.NewTimer(0)
},
}
@ -43,6 +41,7 @@ type Pooler interface {
FreeLen() int
Stats() *Stats
Close() error
Closed() bool
}
type dialer func() (net.Conn, error)
@ -97,13 +96,12 @@ func (p *ConnPool) NewConn() (*Conn, error) {
func (p *ConnPool) PopFree() *Conn {
timer := timers.Get().(*time.Timer)
timer.Reset(p.poolTimeout)
if !timer.Reset(p.poolTimeout) {
<-timer.C
}
select {
case p.queue <- struct{}{}:
if !timer.Stop() {
<-timer.C
}
timers.Put(timer)
case <-timer.C:
timers.Put(timer)
@ -134,20 +132,19 @@ func (p *ConnPool) popFree() *Conn {
// Get returns existed connection from the pool or creates a new one.
func (p *ConnPool) Get() (*Conn, bool, error) {
if p.closed() {
if p.Closed() {
return nil, false, ErrClosed
}
atomic.AddUint32(&p.stats.Requests, 1)
timer := timers.Get().(*time.Timer)
timer.Reset(p.poolTimeout)
if !timer.Reset(p.poolTimeout) {
<-timer.C
}
select {
case p.queue <- struct{}{}:
if !timer.Stop() {
<-timer.C
}
timers.Put(timer)
case <-timer.C:
timers.Put(timer)
@ -244,7 +241,7 @@ func (p *ConnPool) Stats() *Stats {
}
}
func (p *ConnPool) closed() bool {
func (p *ConnPool) Closed() bool {
return atomic.LoadInt32(&p._closed) == 1
}
@ -321,7 +318,7 @@ func (p *ConnPool) reaper(frequency time.Duration) {
defer ticker.Stop()
for _ = range ticker.C {
if p.closed() {
if p.Closed() {
break
}
n, err := p.ReapStaleConns()

View File

@ -12,6 +12,10 @@ func NewSingleConnPool(cn *Conn) *SingleConnPool {
}
}
func (p *SingleConnPool) First() *Conn {
return p.cn
}
func (p *SingleConnPool) Get() (*Conn, bool, error) {
return p.cn, false, nil
}
@ -45,3 +49,7 @@ func (p *SingleConnPool) Stats() *Stats {
func (p *SingleConnPool) Close() error {
return nil
}
func (p *SingleConnPool) Closed() bool {
return false
}

View File

@ -11,7 +11,7 @@ type StickyConnPool struct {
cn *Conn
closed bool
mu sync.Mutex
mx sync.Mutex
}
var _ Pooler = (*StickyConnPool)(nil)
@ -23,9 +23,16 @@ func NewStickyConnPool(pool *ConnPool, reusable bool) *StickyConnPool {
}
}
func (p *StickyConnPool) First() *Conn {
p.mx.Lock()
cn := p.cn
p.mx.Unlock()
return cn
}
func (p *StickyConnPool) Get() (*Conn, bool, error) {
p.mu.Lock()
defer p.mu.Unlock()
defer p.mx.Unlock()
p.mx.Lock()
if p.closed {
return nil, false, ErrClosed
@ -49,12 +56,14 @@ func (p *StickyConnPool) putUpstream() (err error) {
}
func (p *StickyConnPool) Put(cn *Conn) error {
p.mu.Lock()
defer p.mu.Unlock()
defer p.mx.Unlock()
p.mx.Lock()
if p.closed {
return ErrClosed
}
if p.cn != cn {
panic("p.cn != cn")
}
return nil
}
@ -65,19 +74,23 @@ func (p *StickyConnPool) removeUpstream(reason error) error {
}
func (p *StickyConnPool) Remove(cn *Conn, reason error) error {
p.mu.Lock()
defer p.mu.Unlock()
defer p.mx.Unlock()
p.mx.Lock()
if p.closed {
return nil
}
if p.cn == nil {
panic("p.cn == nil")
}
if cn != nil && p.cn != cn {
panic("p.cn != cn")
}
return p.removeUpstream(reason)
}
func (p *StickyConnPool) Len() int {
p.mu.Lock()
defer p.mu.Unlock()
defer p.mx.Unlock()
p.mx.Lock()
if p.cn == nil {
return 0
}
@ -85,9 +98,8 @@ func (p *StickyConnPool) Len() int {
}
func (p *StickyConnPool) FreeLen() int {
p.mu.Lock()
defer p.mu.Unlock()
defer p.mx.Unlock()
p.mx.Lock()
if p.cn == nil {
return 1
}
@ -99,9 +111,8 @@ func (p *StickyConnPool) Stats() *Stats {
}
func (p *StickyConnPool) Close() error {
p.mu.Lock()
defer p.mu.Unlock()
defer p.mx.Unlock()
p.mx.Lock()
if p.closed {
return ErrClosed
}
@ -117,3 +128,10 @@ func (p *StickyConnPool) Close() error {
}
return err
}
func (p *StickyConnPool) Closed() bool {
p.mx.Lock()
closed := p.closed
p.mx.Unlock()
return closed
}

View File

@ -29,14 +29,10 @@ type Reader struct {
func NewReader(rd io.Reader) *Reader {
return &Reader{
src: bufio.NewReader(rd),
buf: make([]byte, 4096),
buf: make([]byte, 0, bufferSize),
}
}
func (r *Reader) Reset(rd io.Reader) {
r.src.Reset(rd)
}
func (p *Reader) PeekBuffered() []byte {
if n := p.src.Buffered(); n != 0 {
b, _ := p.src.Peek(n)
@ -46,12 +42,7 @@ func (p *Reader) PeekBuffered() []byte {
}
func (p *Reader) ReadN(n int) ([]byte, error) {
b, err := readN(p.src, p.buf, n)
if err != nil {
return nil, err
}
p.buf = b
return b, nil
return readN(p.src, p.buf, n)
}
func (p *Reader) ReadLine() ([]byte, error) {
@ -81,11 +72,11 @@ func (p *Reader) ReadReply(m MultiBulkParse) (interface{}, error) {
case ErrorReply:
return nil, ParseErrorReply(line)
case StatusReply:
return parseStatusValue(line), nil
return parseStatusValue(line)
case IntReply:
return parseInt(line[1:], 10, 64)
case StringReply:
return p.readTmpBytesValue(line)
return p.readBytesValue(line)
case ArrayReply:
n, err := parseArrayLen(line)
if err != nil {
@ -120,9 +111,9 @@ func (p *Reader) ReadTmpBytesReply() ([]byte, error) {
case ErrorReply:
return nil, ParseErrorReply(line)
case StringReply:
return p.readTmpBytesValue(line)
return p.readBytesValue(line)
case StatusReply:
return parseStatusValue(line), nil
return parseStatusValue(line)
default:
return nil, fmt.Errorf("redis: can't parse string reply: %.100q", line)
}
@ -219,7 +210,7 @@ func (p *Reader) ReadScanReply() ([]string, uint64, error) {
return keys, cursor, err
}
func (p *Reader) readTmpBytesValue(line []byte) ([]byte, error) {
func (p *Reader) readBytesValue(line []byte) ([]byte, error) {
if isNilReply(line) {
return nil, internal.Nil
}
@ -306,8 +297,8 @@ func ParseErrorReply(line []byte) error {
return internal.RedisError(string(line[1:]))
}
func parseStatusValue(line []byte) []byte {
return line[1:]
func parseStatusValue(line []byte) ([]byte, error) {
return line[1:], nil
}
func parseArrayLen(line []byte) (int64, error) {

View File

@ -3,7 +3,6 @@ package proto
import (
"encoding"
"fmt"
"reflect"
"gopkg.in/redis.v5/internal"
)
@ -106,26 +105,3 @@ func Scan(b []byte, v interface{}) error {
"redis: can't unmarshal %T (consider implementing BinaryUnmarshaler)", v)
}
}
func ScanSlice(data []string, slice interface{}) error {
v := reflect.ValueOf(slice)
if !v.IsValid() {
return fmt.Errorf("redis: ScanSlice(nil)")
}
if v.Kind() != reflect.Ptr {
return fmt.Errorf("redis: ScanSlice(non-pointer %T)", slice)
}
v = v.Elem()
if v.Kind() != reflect.Slice {
return fmt.Errorf("redis: ScanSlice(non-slice %T)", slice)
}
for i, s := range data {
elem := internal.SliceNextElem(v)
if err := Scan([]byte(s), elem.Addr().Interface()); err != nil {
return fmt.Errorf("redis: ScanSlice(index=%d value=%q) failed: %s", i, s, err)
}
}
return nil
}

View File

@ -8,13 +8,11 @@ import (
const bufferSize = 4096
type WriteBuffer struct {
b []byte
}
type WriteBuffer struct{ b []byte }
func NewWriteBuffer() *WriteBuffer {
return &WriteBuffer{
b: make([]byte, 0, 4096),
b: make([]byte, 0, bufferSize),
}
}

View File

@ -1,7 +1,5 @@
package internal
import "reflect"
func ToLower(s string) string {
if isLower(s) {
return s
@ -27,21 +25,3 @@ func isLower(s string) bool {
}
return true
}
func SliceNextElem(v reflect.Value) reflect.Value {
if v.Len() < v.Cap() {
v.Set(v.Slice(0, v.Len()+1))
return v.Index(v.Len() - 1)
}
elemType := v.Type().Elem()
if elemType.Kind() == reflect.Ptr {
elem := reflect.New(elemType.Elem())
v.Set(reflect.Append(v, elem))
return elem.Elem()
}
v.Set(reflect.Append(v, reflect.Zero(elemType)))
return v.Index(v.Len() - 1)
}

View File

@ -3,7 +3,6 @@ package redis
import (
"crypto/tls"
"errors"
"fmt"
"net"
"net/url"
"strconv"
@ -152,7 +151,7 @@ func ParseURL(redisURL string) (*Options, error) {
o.DB = 0
case 1:
if o.DB, err = strconv.Atoi(f[0]); err != nil {
return nil, fmt.Errorf("invalid redis database number: %q", f[0])
return nil, errors.New("invalid redis database number: " + err.Error())
}
default:
return nil, errors.New("invalid redis URL path: " + u.Path)

View File

@ -61,8 +61,8 @@ func (c *Pipeline) discard() error {
// Exec always returns list of commands and error of the first failed
// command if any.
func (c *Pipeline) Exec() ([]Cmder, error) {
c.mu.Lock()
defer c.mu.Unlock()
c.mu.Lock()
if c.closed {
return nil, pool.ErrClosed

39
vendor/gopkg.in/redis.v5/pubsub.go generated vendored
View File

@ -3,7 +3,6 @@ package redis
import (
"fmt"
"net"
"sync"
"time"
"gopkg.in/redis.v5/internal"
@ -15,9 +14,7 @@ import (
// multiple goroutines.
type PubSub struct {
base baseClient
cmd *Cmd
mu sync.Mutex
channels []string
patterns []string
}
@ -98,10 +95,10 @@ func (c *PubSub) Close() error {
return c.base.Close()
}
func (c *PubSub) Ping(payload ...string) error {
func (c *PubSub) Ping(payload string) error {
args := []interface{}{"PING"}
if len(payload) == 1 {
args = append(args, payload[0])
if payload != "" {
args = append(args, payload)
}
cmd := NewCmd(args...)
@ -153,13 +150,7 @@ func (p *Pong) String() string {
return "Pong"
}
func (c *PubSub) newMessage(reply interface{}) (interface{}, error) {
switch reply := reply.(type) {
case string:
return &Pong{
Payload: reply,
}, nil
case []interface{}:
func (c *PubSub) newMessage(reply []interface{}) (interface{}, error) {
switch kind := reply[0].(string); kind {
case "subscribe", "unsubscribe", "psubscribe", "punsubscribe":
return &Subscription{
@ -183,10 +174,7 @@ func (c *PubSub) newMessage(reply interface{}) (interface{}, error) {
Payload: reply[1].(string),
}, nil
default:
return nil, fmt.Errorf("redis: unsupported pubsub message: %q", kind)
}
default:
return nil, fmt.Errorf("redis: unsupported pubsub message: %#v", reply)
return nil, fmt.Errorf("redis: unsupported pubsub notification: %q", kind)
}
}
@ -194,9 +182,7 @@ func (c *PubSub) newMessage(reply interface{}) (interface{}, error) {
// is not received in time. This is low-level API and most clients
// should use ReceiveMessage.
func (c *PubSub) ReceiveTimeout(timeout time.Duration) (interface{}, error) {
if c.cmd == nil {
c.cmd = NewCmd()
}
cmd := NewSliceCmd()
cn, _, err := c.conn()
if err != nil {
@ -204,13 +190,13 @@ func (c *PubSub) ReceiveTimeout(timeout time.Duration) (interface{}, error) {
}
cn.SetReadTimeout(timeout)
err = c.cmd.readReply(cn)
err = cmd.readReply(cn)
c.putConn(cn, err)
if err != nil {
return nil, err
}
return c.newMessage(c.cmd.Val())
return c.newMessage(cmd.Val())
}
// Receive returns a message as a Subscription, Message, Pong or error.
@ -239,14 +225,14 @@ func (c *PubSub) receiveMessage(timeout time.Duration) (*Message, error) {
errNum++
if errNum < 3 {
if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
err := c.Ping()
err := c.Ping("")
if err != nil {
internal.Logf("PubSub.Ping failed: %s", err)
}
}
} else {
// 3 consequent errors - connection is broken or
// Redis Server is down.
// 3 consequent errors - connection is bad
// and/or Redis Server is down.
// Sleep to not exceed max number of open connections.
time.Sleep(time.Second)
}
@ -270,6 +256,9 @@ func (c *PubSub) receiveMessage(timeout time.Duration) (*Message, error) {
}
func (c *PubSub) resubscribe() {
if c.base.closed() {
return
}
if len(c.channels) > 0 {
if err := c.Subscribe(c.channels...); err != nil {
internal.Logf("Subscribe failed: %s", err)

19
vendor/gopkg.in/redis.v5/redis.go generated vendored
View File

@ -17,6 +17,14 @@ func SetLogger(logger *log.Logger) {
internal.Logger = logger
}
type baseClient struct {
connPool pool.Pooler
opt *Options
process func(Cmder) error
onClose func() error // hook called when client is closed
}
func (c *baseClient) String() string {
return fmt.Sprintf("Redis<%s db:%d>", c.getAddr(), c.opt.DB)
}
@ -126,6 +134,10 @@ func (c *baseClient) cmdTimeout(cmd Cmder) time.Duration {
}
}
func (c *baseClient) closed() bool {
return c.connPool.Closed()
}
// Close closes the client, releasing any open resources.
//
// It is rare to Close a Client, as the Client is meant to be
@ -297,13 +309,6 @@ func NewClient(opt *Options) *Client {
return newClient(opt, newConnPool(opt))
}
func (c *Client) copy() *Client {
c2 := new(Client)
*c2 = *c
c2.cmdable.process = c2.Process
return c2
}
// PoolStats returns connection pool stats.
func (c *Client) PoolStats() *PoolStats {
s := c.connPool.Stats()

View File

@ -1,35 +0,0 @@
// +build go1.7
package redis
import (
"context"
"gopkg.in/redis.v5/internal/pool"
)
type baseClient struct {
connPool pool.Pooler
opt *Options
process func(Cmder) error
onClose func() error // hook called when client is closed
ctx context.Context
}
func (c *Client) Context() context.Context {
if c.ctx != nil {
return c.ctx
}
return context.Background()
}
func (c *Client) WithContext(ctx context.Context) *Client {
if ctx == nil {
panic("nil context")
}
c2 := c.copy()
c2.ctx = ctx
return c2
}

View File

@ -1,15 +0,0 @@
// +build !go1.7
package redis
import (
"gopkg.in/redis.v5/internal/pool"
)
type baseClient struct {
connPool pool.Pooler
opt *Options
process func(Cmder) error
onClose func() error // hook called when client is closed
}

2
vendor/gopkg.in/redis.v5/ring.go generated vendored
View File

@ -328,8 +328,8 @@ func (c *Ring) heartbeat() {
// It is rare to Close a Ring, as the Ring is meant to be long-lived
// and shared between many goroutines.
func (c *Ring) Close() error {
c.mu.Lock()
defer c.mu.Unlock()
c.mu.Lock()
if c.closed {
return nil

10
vendor/gopkg.in/redis.v5/sentinel.go generated vendored
View File

@ -162,8 +162,8 @@ func (d *sentinelFailover) Pool() *pool.ConnPool {
}
func (d *sentinelFailover) MasterAddr() (string, error) {
d.mu.Lock()
defer d.mu.Unlock()
d.mu.Lock()
// Try last working sentinel.
if d.sentinel != nil {
@ -258,7 +258,7 @@ func (d *sentinelFailover) discoverSentinels(sentinel *sentinelClient) {
// closeOldConns closes connections to the old master after failover switch.
func (d *sentinelFailover) closeOldConns(newMaster string) {
// Good connections that should be put back to the pool. They
// can't be put immediately, because pool.PopFree will return them
// can't be put immediately, because pool.First will return them
// again on next iteration.
cnsToPut := make([]*pool.Conn, 0)
@ -267,10 +267,10 @@ func (d *sentinelFailover) closeOldConns(newMaster string) {
if cn == nil {
break
}
if cn.RemoteAddr().String() != newMaster {
if cn.NetConn.RemoteAddr().String() != newMaster {
err := fmt.Errorf(
"sentinel: closing connection to the old master %s",
cn.RemoteAddr(),
cn.NetConn.RemoteAddr(),
)
internal.Logf(err.Error())
d.pool.Remove(cn, err)
@ -289,10 +289,8 @@ func (d *sentinelFailover) listen(sentinel *sentinelClient) {
for {
if pubsub == nil {
pubsub = sentinel.PubSub()
if err := pubsub.Subscribe("+switch-master"); err != nil {
internal.Logf("sentinel: Subscribe failed: %s", err)
pubsub.Close()
d.resetSentinel()
return
}

View File

@ -9,7 +9,7 @@ type OsuBool bool
// UnmarshalJSON converts `"0"` to false and `"1"` to true.
func (o *OsuBool) UnmarshalJSON(data []byte) error {
if string(data) == `0` {
if string(data) == `"0"` {
*o = false
return nil
}

44
vendor/vendor.json vendored
View File

@ -99,10 +99,10 @@
"revisionTime": "2016-10-10T15:00:23Z"
},
{
"checksumSHA1": "9ujFdggUmv6hyAgJ+Bjugh0UZAc=",
"checksumSHA1": "kUH66xItMsO3QDibGHCWZHa9B3o=",
"path": "github.com/thehowl/go-osuapi",
"revision": "23480db9e43c9a8080cbb681ceaed855e5fca7f3",
"revisionTime": "2017-03-12T09:17:38Z"
"revision": "77ef7867f23cd52e80dcf97e62447d3b36b1d26a",
"revisionTime": "2016-10-17T20:25:41Z"
},
{
"checksumSHA1": "LTOa3BADhwvT0wFCknPueQALm8I=",
@ -141,46 +141,46 @@
"revisionTime": "2017-01-10T16:23:43Z"
},
{
"checksumSHA1": "OU/wHTJqhyQfyRnXMVWx1Ox06kQ=",
"checksumSHA1": "4+WlWTIczvywOonXZGH34YdCf6s=",
"path": "gopkg.in/redis.v5",
"revision": "a16aeec10ff407b1e7be6dd35797ccf5426ef0f0",
"revisionTime": "2017-03-04T11:38:25Z"
"revision": "6da05abbaa03e90e5878f0ab711478698609fe96",
"revisionTime": "2017-01-13T11:52:40Z"
},
{
"checksumSHA1": "efyYmNqK7vcPhXW4KXfwbdA1wr4=",
"checksumSHA1": "MQyhe1N+NO0+uyJiEc6M2WGfb3s=",
"path": "gopkg.in/redis.v5/internal",
"revision": "a16aeec10ff407b1e7be6dd35797ccf5426ef0f0",
"revisionTime": "2017-03-04T11:38:25Z"
"revision": "6da05abbaa03e90e5878f0ab711478698609fe96",
"revisionTime": "2017-01-13T11:52:40Z"
},
{
"checksumSHA1": "2Ek4SixeRSKOX3mUiBMs3Aw+Guc=",
"path": "gopkg.in/redis.v5/internal/consistenthash",
"revision": "a16aeec10ff407b1e7be6dd35797ccf5426ef0f0",
"revisionTime": "2017-03-04T11:38:25Z"
"revision": "6da05abbaa03e90e5878f0ab711478698609fe96",
"revisionTime": "2017-01-13T11:52:40Z"
},
{
"checksumSHA1": "rJYVKcBrwYUGl7nuuusmZGrt8mY=",
"path": "gopkg.in/redis.v5/internal/hashtag",
"revision": "a16aeec10ff407b1e7be6dd35797ccf5426ef0f0",
"revisionTime": "2017-03-04T11:38:25Z"
"revision": "6da05abbaa03e90e5878f0ab711478698609fe96",
"revisionTime": "2017-01-13T11:52:40Z"
},
{
"checksumSHA1": "zsH5BF9qc31R7eEEVYLsjbIigDQ=",
"checksumSHA1": "yLZQUKNxXzwGlzfXhWC0Mwme2nw=",
"path": "gopkg.in/redis.v5/internal/pool",
"revision": "a16aeec10ff407b1e7be6dd35797ccf5426ef0f0",
"revisionTime": "2017-03-04T11:38:25Z"
"revision": "6da05abbaa03e90e5878f0ab711478698609fe96",
"revisionTime": "2017-01-13T11:52:40Z"
},
{
"checksumSHA1": "EqPdu5g8NhzxQOMCvzbreTQlzVE=",
"checksumSHA1": "KoSfO3h/KmlaGphIM4KzBGm65O4=",
"path": "gopkg.in/redis.v5/internal/proto",
"revision": "a16aeec10ff407b1e7be6dd35797ccf5426ef0f0",
"revisionTime": "2017-03-04T11:38:25Z"
"revision": "6da05abbaa03e90e5878f0ab711478698609fe96",
"revisionTime": "2017-01-13T11:52:40Z"
},
{
"checksumSHA1": "va1m3wm/nxA5IEC/3r4GQeT/+Ro=",
"checksumSHA1": "IVLVpxH6lCjsiVVIl/qf8ftjXbg=",
"path": "gopkg.in/thehowl/go-osuapi.v1",
"revision": "23480db9e43c9a8080cbb681ceaed855e5fca7f3",
"revisionTime": "2017-03-12T09:17:38Z"
"revision": "77ef7867f23cd52e80dcf97e62447d3b36b1d26a",
"revisionTime": "2016-10-17T20:25:41Z"
},
{
"checksumSHA1": "SI9tgNMlnMhxP7t6cAGuDjvoAHg=",