summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/go-redis/redis/internal
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/go-redis/redis/internal')
-rw-r--r--vendor/github.com/go-redis/redis/internal/consistenthash/consistenthash_test.go110
-rw-r--r--vendor/github.com/go-redis/redis/internal/error.go14
-rw-r--r--vendor/github.com/go-redis/redis/internal/hashtag/hashtag_test.go74
-rw-r--r--vendor/github.com/go-redis/redis/internal/internal_test.go18
-rw-r--r--vendor/github.com/go-redis/redis/internal/pool/bench_test.go80
-rw-r--r--vendor/github.com/go-redis/redis/internal/pool/main_test.go35
-rw-r--r--vendor/github.com/go-redis/redis/internal/pool/pool_test.go241
-rw-r--r--vendor/github.com/go-redis/redis/internal/proto/proto_test.go13
-rw-r--r--vendor/github.com/go-redis/redis/internal/proto/reader.go48
-rw-r--r--vendor/github.com/go-redis/redis/internal/proto/reader_test.go87
-rw-r--r--vendor/github.com/go-redis/redis/internal/proto/scan.go63
-rw-r--r--vendor/github.com/go-redis/redis/internal/proto/scan_test.go48
-rw-r--r--vendor/github.com/go-redis/redis/internal/proto/write_buffer.go18
-rw-r--r--vendor/github.com/go-redis/redis/internal/proto/write_buffer_test.go63
-rw-r--r--vendor/github.com/go-redis/redis/internal/singleflight/singleflight.go64
-rw-r--r--vendor/github.com/go-redis/redis/internal/util.go37
-rw-r--r--vendor/github.com/go-redis/redis/internal/util/safe.go (renamed from vendor/github.com/go-redis/redis/internal/safe.go)2
-rw-r--r--vendor/github.com/go-redis/redis/internal/util/strconv.go19
-rw-r--r--vendor/github.com/go-redis/redis/internal/util/unsafe.go (renamed from vendor/github.com/go-redis/redis/internal/unsafe.go)2
19 files changed, 171 insertions, 865 deletions
diff --git a/vendor/github.com/go-redis/redis/internal/consistenthash/consistenthash_test.go b/vendor/github.com/go-redis/redis/internal/consistenthash/consistenthash_test.go
deleted file mode 100644
index 1a37fd7ff..000000000
--- a/vendor/github.com/go-redis/redis/internal/consistenthash/consistenthash_test.go
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
-Copyright 2013 Google Inc.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-package consistenthash
-
-import (
- "fmt"
- "strconv"
- "testing"
-)
-
-func TestHashing(t *testing.T) {
-
- // Override the hash function to return easier to reason about values. Assumes
- // the keys can be converted to an integer.
- hash := New(3, func(key []byte) uint32 {
- i, err := strconv.Atoi(string(key))
- if err != nil {
- panic(err)
- }
- return uint32(i)
- })
-
- // Given the above hash function, this will give replicas with "hashes":
- // 2, 4, 6, 12, 14, 16, 22, 24, 26
- hash.Add("6", "4", "2")
-
- testCases := map[string]string{
- "2": "2",
- "11": "2",
- "23": "4",
- "27": "2",
- }
-
- for k, v := range testCases {
- if hash.Get(k) != v {
- t.Errorf("Asking for %s, should have yielded %s", k, v)
- }
- }
-
- // Adds 8, 18, 28
- hash.Add("8")
-
- // 27 should now map to 8.
- testCases["27"] = "8"
-
- for k, v := range testCases {
- if hash.Get(k) != v {
- t.Errorf("Asking for %s, should have yielded %s", k, v)
- }
- }
-
-}
-
-func TestConsistency(t *testing.T) {
- hash1 := New(1, nil)
- hash2 := New(1, nil)
-
- hash1.Add("Bill", "Bob", "Bonny")
- hash2.Add("Bob", "Bonny", "Bill")
-
- if hash1.Get("Ben") != hash2.Get("Ben") {
- t.Errorf("Fetching 'Ben' from both hashes should be the same")
- }
-
- hash2.Add("Becky", "Ben", "Bobby")
-
- if hash1.Get("Ben") != hash2.Get("Ben") ||
- hash1.Get("Bob") != hash2.Get("Bob") ||
- hash1.Get("Bonny") != hash2.Get("Bonny") {
- t.Errorf("Direct matches should always return the same entry")
- }
-
-}
-
-func BenchmarkGet8(b *testing.B) { benchmarkGet(b, 8) }
-func BenchmarkGet32(b *testing.B) { benchmarkGet(b, 32) }
-func BenchmarkGet128(b *testing.B) { benchmarkGet(b, 128) }
-func BenchmarkGet512(b *testing.B) { benchmarkGet(b, 512) }
-
-func benchmarkGet(b *testing.B, shards int) {
-
- hash := New(50, nil)
-
- var buckets []string
- for i := 0; i < shards; i++ {
- buckets = append(buckets, fmt.Sprintf("shard-%d", i))
- }
-
- hash.Add(buckets...)
-
- b.ResetTimer()
-
- for i := 0; i < b.N; i++ {
- hash.Get(buckets[i&(shards-1)])
- }
-}
diff --git a/vendor/github.com/go-redis/redis/internal/error.go b/vendor/github.com/go-redis/redis/internal/error.go
index 0898eeb62..7b419577e 100644
--- a/vendor/github.com/go-redis/redis/internal/error.go
+++ b/vendor/github.com/go-redis/redis/internal/error.go
@@ -4,13 +4,9 @@ import (
"io"
"net"
"strings"
-)
-
-const Nil = RedisError("redis: nil")
-
-type RedisError string
-func (e RedisError) Error() string { return string(e) }
+ "github.com/go-redis/redis/internal/proto"
+)
func IsRetryableError(err error, retryNetError bool) bool {
if IsNetworkError(err) {
@@ -30,7 +26,7 @@ func IsRetryableError(err error, retryNetError bool) bool {
}
func IsRedisError(err error) bool {
- _, ok := err.(RedisError)
+ _, ok := err.(proto.RedisError)
return ok
}
@@ -42,6 +38,10 @@ func IsNetworkError(err error) bool {
return ok
}
+func IsReadOnlyError(err error) bool {
+ return strings.HasPrefix(err.Error(), "READONLY ")
+}
+
func IsBadConn(err error, allowTimeout bool) bool {
if err == nil {
return false
diff --git a/vendor/github.com/go-redis/redis/internal/hashtag/hashtag_test.go b/vendor/github.com/go-redis/redis/internal/hashtag/hashtag_test.go
deleted file mode 100644
index 7f0fedf31..000000000
--- a/vendor/github.com/go-redis/redis/internal/hashtag/hashtag_test.go
+++ /dev/null
@@ -1,74 +0,0 @@
-package hashtag
-
-import (
- "math/rand"
- "testing"
-
- . "github.com/onsi/ginkgo"
- . "github.com/onsi/gomega"
-)
-
-func TestGinkgoSuite(t *testing.T) {
- RegisterFailHandler(Fail)
- RunSpecs(t, "hashtag")
-}
-
-var _ = Describe("CRC16", func() {
-
- // http://redis.io/topics/cluster-spec#keys-distribution-model
- It("should calculate CRC16", func() {
- tests := []struct {
- s string
- n uint16
- }{
- {"123456789", 0x31C3},
- {string([]byte{83, 153, 134, 118, 229, 214, 244, 75, 140, 37, 215, 215}), 21847},
- }
-
- for _, test := range tests {
- Expect(crc16sum(test.s)).To(Equal(test.n), "for %s", test.s)
- }
- })
-
-})
-
-var _ = Describe("HashSlot", func() {
-
- It("should calculate hash slots", func() {
- tests := []struct {
- key string
- slot int
- }{
- {"123456789", 12739},
- {"{}foo", 9500},
- {"foo{}", 5542},
- {"foo{}{bar}", 8363},
- {"", 10503},
- {"", 5176},
- {string([]byte{83, 153, 134, 118, 229, 214, 244, 75, 140, 37, 215, 215}), 5463},
- }
- // Empty keys receive random slot.
- rand.Seed(100)
-
- for _, test := range tests {
- Expect(Slot(test.key)).To(Equal(test.slot), "for %s", test.key)
- }
- })
-
- It("should extract keys from tags", func() {
- tests := []struct {
- one, two string
- }{
- {"foo{bar}", "bar"},
- {"{foo}bar", "foo"},
- {"{user1000}.following", "{user1000}.followers"},
- {"foo{{bar}}zap", "{bar"},
- {"foo{bar}{zap}", "bar"},
- }
-
- for _, test := range tests {
- Expect(Slot(test.one)).To(Equal(Slot(test.two)), "for %s <-> %s", test.one, test.two)
- }
- })
-
-})
diff --git a/vendor/github.com/go-redis/redis/internal/internal_test.go b/vendor/github.com/go-redis/redis/internal/internal_test.go
deleted file mode 100644
index 56ff611e1..000000000
--- a/vendor/github.com/go-redis/redis/internal/internal_test.go
+++ /dev/null
@@ -1,18 +0,0 @@
-package internal
-
-import (
- "testing"
- "time"
-
- . "github.com/onsi/gomega"
-)
-
-func TestRetryBackoff(t *testing.T) {
- RegisterTestingT(t)
-
- for i := -1; i <= 16; i++ {
- backoff := RetryBackoff(i, time.Millisecond, 512*time.Millisecond)
- Expect(backoff >= 0).To(BeTrue())
- Expect(backoff <= 512*time.Millisecond).To(BeTrue())
- }
-}
diff --git a/vendor/github.com/go-redis/redis/internal/pool/bench_test.go b/vendor/github.com/go-redis/redis/internal/pool/bench_test.go
deleted file mode 100644
index e0bb52446..000000000
--- a/vendor/github.com/go-redis/redis/internal/pool/bench_test.go
+++ /dev/null
@@ -1,80 +0,0 @@
-package pool_test
-
-import (
- "testing"
- "time"
-
- "github.com/go-redis/redis/internal/pool"
-)
-
-func benchmarkPoolGetPut(b *testing.B, poolSize int) {
- connPool := pool.NewConnPool(&pool.Options{
- Dialer: dummyDialer,
- PoolSize: poolSize,
- PoolTimeout: time.Second,
- IdleTimeout: time.Hour,
- IdleCheckFrequency: time.Hour,
- })
-
- b.ResetTimer()
-
- b.RunParallel(func(pb *testing.PB) {
- for pb.Next() {
- cn, _, err := connPool.Get()
- if err != nil {
- b.Fatal(err)
- }
- if err = connPool.Put(cn); err != nil {
- b.Fatal(err)
- }
- }
- })
-}
-
-func BenchmarkPoolGetPut10Conns(b *testing.B) {
- benchmarkPoolGetPut(b, 10)
-}
-
-func BenchmarkPoolGetPut100Conns(b *testing.B) {
- benchmarkPoolGetPut(b, 100)
-}
-
-func BenchmarkPoolGetPut1000Conns(b *testing.B) {
- benchmarkPoolGetPut(b, 1000)
-}
-
-func benchmarkPoolGetRemove(b *testing.B, poolSize int) {
- connPool := pool.NewConnPool(&pool.Options{
- Dialer: dummyDialer,
- PoolSize: poolSize,
- PoolTimeout: time.Second,
- IdleTimeout: time.Hour,
- IdleCheckFrequency: time.Hour,
- })
-
- b.ResetTimer()
-
- b.RunParallel(func(pb *testing.PB) {
- for pb.Next() {
- cn, _, err := connPool.Get()
- if err != nil {
- b.Fatal(err)
- }
- if err := connPool.Remove(cn); err != nil {
- b.Fatal(err)
- }
- }
- })
-}
-
-func BenchmarkPoolGetRemove10Conns(b *testing.B) {
- benchmarkPoolGetRemove(b, 10)
-}
-
-func BenchmarkPoolGetRemove100Conns(b *testing.B) {
- benchmarkPoolGetRemove(b, 100)
-}
-
-func BenchmarkPoolGetRemove1000Conns(b *testing.B) {
- benchmarkPoolGetRemove(b, 1000)
-}
diff --git a/vendor/github.com/go-redis/redis/internal/pool/main_test.go b/vendor/github.com/go-redis/redis/internal/pool/main_test.go
deleted file mode 100644
index 43afe3fa9..000000000
--- a/vendor/github.com/go-redis/redis/internal/pool/main_test.go
+++ /dev/null
@@ -1,35 +0,0 @@
-package pool_test
-
-import (
- "net"
- "sync"
- "testing"
-
- . "github.com/onsi/ginkgo"
- . "github.com/onsi/gomega"
-)
-
-func TestGinkgoSuite(t *testing.T) {
- RegisterFailHandler(Fail)
- RunSpecs(t, "pool")
-}
-
-func perform(n int, cbs ...func(int)) {
- var wg sync.WaitGroup
- for _, cb := range cbs {
- for i := 0; i < n; i++ {
- wg.Add(1)
- go func(cb func(int), i int) {
- defer GinkgoRecover()
- defer wg.Done()
-
- cb(i)
- }(cb, i)
- }
- }
- wg.Wait()
-}
-
-func dummyDialer() (net.Conn, error) {
- return &net.TCPConn{}, nil
-}
diff --git a/vendor/github.com/go-redis/redis/internal/pool/pool_test.go b/vendor/github.com/go-redis/redis/internal/pool/pool_test.go
deleted file mode 100644
index 68c9a1bef..000000000
--- a/vendor/github.com/go-redis/redis/internal/pool/pool_test.go
+++ /dev/null
@@ -1,241 +0,0 @@
-package pool_test
-
-import (
- "testing"
- "time"
-
- "github.com/go-redis/redis/internal/pool"
-
- . "github.com/onsi/ginkgo"
- . "github.com/onsi/gomega"
-)
-
-var _ = Describe("ConnPool", func() {
- var connPool *pool.ConnPool
-
- BeforeEach(func() {
- connPool = pool.NewConnPool(&pool.Options{
- Dialer: dummyDialer,
- PoolSize: 10,
- PoolTimeout: time.Hour,
- IdleTimeout: time.Millisecond,
- IdleCheckFrequency: time.Millisecond,
- })
- })
-
- AfterEach(func() {
- connPool.Close()
- })
-
- It("should unblock client when conn is removed", func() {
- // Reserve one connection.
- cn, _, err := connPool.Get()
- Expect(err).NotTo(HaveOccurred())
-
- // Reserve all other connections.
- var cns []*pool.Conn
- for i := 0; i < 9; i++ {
- cn, _, err := connPool.Get()
- Expect(err).NotTo(HaveOccurred())
- cns = append(cns, cn)
- }
-
- started := make(chan bool, 1)
- done := make(chan bool, 1)
- go func() {
- defer GinkgoRecover()
-
- started <- true
- _, _, err := connPool.Get()
- Expect(err).NotTo(HaveOccurred())
- done <- true
-
- err = connPool.Put(cn)
- Expect(err).NotTo(HaveOccurred())
- }()
- <-started
-
- // Check that Get is blocked.
- select {
- case <-done:
- Fail("Get is not blocked")
- default:
- // ok
- }
-
- err = connPool.Remove(cn)
- Expect(err).NotTo(HaveOccurred())
-
- // Check that Ping is unblocked.
- select {
- case <-done:
- // ok
- case <-time.After(time.Second):
- Fail("Get is not unblocked")
- }
-
- for _, cn := range cns {
- err = connPool.Put(cn)
- Expect(err).NotTo(HaveOccurred())
- }
- })
-})
-
-var _ = Describe("conns reaper", func() {
- const idleTimeout = time.Minute
-
- var connPool *pool.ConnPool
- var conns, idleConns, closedConns []*pool.Conn
-
- BeforeEach(func() {
- conns = nil
- closedConns = nil
-
- connPool = pool.NewConnPool(&pool.Options{
- Dialer: dummyDialer,
- PoolSize: 10,
- PoolTimeout: time.Second,
- IdleTimeout: idleTimeout,
- IdleCheckFrequency: time.Hour,
-
- OnClose: func(cn *pool.Conn) error {
- closedConns = append(closedConns, cn)
- return nil
- },
- })
-
- // add stale connections
- idleConns = nil
- for i := 0; i < 3; i++ {
- cn, _, err := connPool.Get()
- Expect(err).NotTo(HaveOccurred())
- cn.SetUsedAt(time.Now().Add(-2 * idleTimeout))
- conns = append(conns, cn)
- idleConns = append(idleConns, cn)
- }
-
- // add fresh connections
- for i := 0; i < 3; i++ {
- cn, _, err := connPool.Get()
- Expect(err).NotTo(HaveOccurred())
- conns = append(conns, cn)
- }
-
- for _, cn := range conns {
- Expect(connPool.Put(cn)).NotTo(HaveOccurred())
- }
-
- Expect(connPool.Len()).To(Equal(6))
- Expect(connPool.FreeLen()).To(Equal(6))
-
- n, err := connPool.ReapStaleConns()
- Expect(err).NotTo(HaveOccurred())
- Expect(n).To(Equal(3))
- })
-
- AfterEach(func() {
- _ = connPool.Close()
- Expect(connPool.Len()).To(Equal(0))
- Expect(connPool.FreeLen()).To(Equal(0))
- Expect(len(closedConns)).To(Equal(len(conns)))
- Expect(closedConns).To(ConsistOf(conns))
- })
-
- It("reaps stale connections", func() {
- Expect(connPool.Len()).To(Equal(3))
- Expect(connPool.FreeLen()).To(Equal(3))
- })
-
- It("does not reap fresh connections", func() {
- n, err := connPool.ReapStaleConns()
- Expect(err).NotTo(HaveOccurred())
- Expect(n).To(Equal(0))
- })
-
- It("stale connections are closed", func() {
- Expect(len(closedConns)).To(Equal(len(idleConns)))
- Expect(closedConns).To(ConsistOf(idleConns))
- })
-
- It("pool is functional", func() {
- for j := 0; j < 3; j++ {
- var freeCns []*pool.Conn
- for i := 0; i < 3; i++ {
- cn, _, err := connPool.Get()
- Expect(err).NotTo(HaveOccurred())
- Expect(cn).NotTo(BeNil())
- freeCns = append(freeCns, cn)
- }
-
- Expect(connPool.Len()).To(Equal(3))
- Expect(connPool.FreeLen()).To(Equal(0))
-
- cn, _, err := connPool.Get()
- Expect(err).NotTo(HaveOccurred())
- Expect(cn).NotTo(BeNil())
- conns = append(conns, cn)
-
- Expect(connPool.Len()).To(Equal(4))
- Expect(connPool.FreeLen()).To(Equal(0))
-
- err = connPool.Remove(cn)
- Expect(err).NotTo(HaveOccurred())
-
- Expect(connPool.Len()).To(Equal(3))
- Expect(connPool.FreeLen()).To(Equal(0))
-
- for _, cn := range freeCns {
- err := connPool.Put(cn)
- Expect(err).NotTo(HaveOccurred())
- }
-
- Expect(connPool.Len()).To(Equal(3))
- Expect(connPool.FreeLen()).To(Equal(3))
- }
- })
-})
-
-var _ = Describe("race", func() {
- var connPool *pool.ConnPool
- var C, N int
-
- BeforeEach(func() {
- C, N = 10, 1000
- if testing.Short() {
- C = 4
- N = 100
- }
- })
-
- AfterEach(func() {
- connPool.Close()
- })
-
- It("does not happen on Get, Put, and Remove", func() {
- connPool = pool.NewConnPool(&pool.Options{
- Dialer: dummyDialer,
- PoolSize: 10,
- PoolTimeout: time.Minute,
- IdleTimeout: time.Millisecond,
- IdleCheckFrequency: time.Millisecond,
- })
-
- perform(C, func(id int) {
- for i := 0; i < N; i++ {
- cn, _, err := connPool.Get()
- Expect(err).NotTo(HaveOccurred())
- if err == nil {
- Expect(connPool.Put(cn)).NotTo(HaveOccurred())
- }
- }
- }, func(id int) {
- for i := 0; i < N; i++ {
- cn, _, err := connPool.Get()
- Expect(err).NotTo(HaveOccurred())
- if err == nil {
- Expect(connPool.Remove(cn)).NotTo(HaveOccurred())
- }
- }
- })
- })
-})
diff --git a/vendor/github.com/go-redis/redis/internal/proto/proto_test.go b/vendor/github.com/go-redis/redis/internal/proto/proto_test.go
deleted file mode 100644
index c9a820eb1..000000000
--- a/vendor/github.com/go-redis/redis/internal/proto/proto_test.go
+++ /dev/null
@@ -1,13 +0,0 @@
-package proto_test
-
-import (
- "testing"
-
- . "github.com/onsi/ginkgo"
- . "github.com/onsi/gomega"
-)
-
-func TestGinkgoSuite(t *testing.T) {
- RegisterFailHandler(Fail)
- RunSpecs(t, "proto")
-}
diff --git a/vendor/github.com/go-redis/redis/internal/proto/reader.go b/vendor/github.com/go-redis/redis/internal/proto/reader.go
index e5ae8a03e..d5d695358 100644
--- a/vendor/github.com/go-redis/redis/internal/proto/reader.go
+++ b/vendor/github.com/go-redis/redis/internal/proto/reader.go
@@ -6,7 +6,7 @@ import (
"io"
"strconv"
- "github.com/go-redis/redis/internal"
+ "github.com/go-redis/redis/internal/util"
)
const bytesAllocLimit = 1024 * 1024 // 1mb
@@ -19,6 +19,16 @@ const (
ArrayReply = '*'
)
+//------------------------------------------------------------------------------
+
+const Nil = RedisError("redis: nil")
+
+type RedisError string
+
+func (e RedisError) Error() string { return string(e) }
+
+//------------------------------------------------------------------------------
+
type MultiBulkParse func(*Reader, int64) (interface{}, error)
type Reader struct {
@@ -66,7 +76,7 @@ func (r *Reader) ReadLine() ([]byte, error) {
return nil, fmt.Errorf("redis: reply is empty")
}
if isNilReply(line) {
- return nil, internal.Nil
+ return nil, Nil
}
return line, nil
}
@@ -83,7 +93,7 @@ func (r *Reader) ReadReply(m MultiBulkParse) (interface{}, error) {
case StatusReply:
return parseStatusValue(line), nil
case IntReply:
- return parseInt(line[1:], 10, 64)
+ return util.ParseInt(line[1:], 10, 64)
case StringReply:
return r.readTmpBytesValue(line)
case ArrayReply:
@@ -105,7 +115,7 @@ func (r *Reader) ReadIntReply() (int64, error) {
case ErrorReply:
return 0, ParseErrorReply(line)
case IntReply:
- return parseInt(line[1:], 10, 64)
+ return util.ParseInt(line[1:], 10, 64)
default:
return 0, fmt.Errorf("redis: can't parse int reply: %.100q", line)
}
@@ -151,7 +161,7 @@ func (r *Reader) ReadFloatReply() (float64, error) {
if err != nil {
return 0, err
}
- return parseFloat(b, 64)
+ return util.ParseFloat(b, 64)
}
func (r *Reader) ReadArrayReply(m MultiBulkParse) (interface{}, error) {
@@ -221,7 +231,7 @@ func (r *Reader) ReadScanReply() ([]string, uint64, error) {
func (r *Reader) readTmpBytesValue(line []byte) ([]byte, error) {
if isNilReply(line) {
- return nil, internal.Nil
+ return nil, Nil
}
replyLen, err := strconv.Atoi(string(line[1:]))
@@ -241,7 +251,7 @@ func (r *Reader) ReadInt() (int64, error) {
if err != nil {
return 0, err
}
- return parseInt(b, 10, 64)
+ return util.ParseInt(b, 10, 64)
}
func (r *Reader) ReadUint() (uint64, error) {
@@ -249,7 +259,7 @@ func (r *Reader) ReadUint() (uint64, error) {
if err != nil {
return 0, err
}
- return parseUint(b, 10, 64)
+ return util.ParseUint(b, 10, 64)
}
// --------------------------------------------------------------------
@@ -303,7 +313,7 @@ func isNilReply(b []byte) bool {
}
func ParseErrorReply(line []byte) error {
- return internal.RedisError(string(line[1:]))
+ return RedisError(string(line[1:]))
}
func parseStatusValue(line []byte) []byte {
@@ -312,23 +322,7 @@ func parseStatusValue(line []byte) []byte {
func parseArrayLen(line []byte) (int64, error) {
if isNilReply(line) {
- return 0, internal.Nil
+ return 0, Nil
}
- return parseInt(line[1:], 10, 64)
-}
-
-func atoi(b []byte) (int, error) {
- return strconv.Atoi(internal.BytesToString(b))
-}
-
-func parseInt(b []byte, base int, bitSize int) (int64, error) {
- return strconv.ParseInt(internal.BytesToString(b), base, bitSize)
-}
-
-func parseUint(b []byte, base int, bitSize int) (uint64, error) {
- return strconv.ParseUint(internal.BytesToString(b), base, bitSize)
-}
-
-func parseFloat(b []byte, bitSize int) (float64, error) {
- return strconv.ParseFloat(internal.BytesToString(b), bitSize)
+ return util.ParseInt(line[1:], 10, 64)
}
diff --git a/vendor/github.com/go-redis/redis/internal/proto/reader_test.go b/vendor/github.com/go-redis/redis/internal/proto/reader_test.go
deleted file mode 100644
index 8d2d71be9..000000000
--- a/vendor/github.com/go-redis/redis/internal/proto/reader_test.go
+++ /dev/null
@@ -1,87 +0,0 @@
-package proto_test
-
-import (
- "bytes"
- "strings"
- "testing"
-
- "github.com/go-redis/redis/internal/proto"
-
- . "github.com/onsi/ginkgo"
- . "github.com/onsi/gomega"
-)
-
-var _ = Describe("Reader", func() {
-
- It("should read n bytes", func() {
- data, err := proto.NewReader(strings.NewReader("ABCDEFGHIJKLMNO")).ReadN(10)
- Expect(err).NotTo(HaveOccurred())
- Expect(len(data)).To(Equal(10))
- Expect(string(data)).To(Equal("ABCDEFGHIJ"))
-
- data, err = proto.NewReader(strings.NewReader(strings.Repeat("x", 8192))).ReadN(6000)
- Expect(err).NotTo(HaveOccurred())
- Expect(len(data)).To(Equal(6000))
- })
-
- It("should read lines", func() {
- p := proto.NewReader(strings.NewReader("$5\r\nhello\r\n"))
-
- data, err := p.ReadLine()
- Expect(err).NotTo(HaveOccurred())
- Expect(string(data)).To(Equal("$5"))
-
- data, err = p.ReadLine()
- Expect(err).NotTo(HaveOccurred())
- Expect(string(data)).To(Equal("hello"))
- })
-
-})
-
-func BenchmarkReader_ParseReply_Status(b *testing.B) {
- benchmarkParseReply(b, "+OK\r\n", nil, false)
-}
-
-func BenchmarkReader_ParseReply_Int(b *testing.B) {
- benchmarkParseReply(b, ":1\r\n", nil, false)
-}
-
-func BenchmarkReader_ParseReply_Error(b *testing.B) {
- benchmarkParseReply(b, "-Error message\r\n", nil, true)
-}
-
-func BenchmarkReader_ParseReply_String(b *testing.B) {
- benchmarkParseReply(b, "$5\r\nhello\r\n", nil, false)
-}
-
-func BenchmarkReader_ParseReply_Slice(b *testing.B) {
- benchmarkParseReply(b, "*2\r\n$5\r\nhello\r\n$5\r\nworld\r\n", multiBulkParse, false)
-}
-
-func benchmarkParseReply(b *testing.B, reply string, m proto.MultiBulkParse, wanterr bool) {
- buf := new(bytes.Buffer)
- for i := 0; i < b.N; i++ {
- buf.WriteString(reply)
- }
- p := proto.NewReader(buf)
- b.ResetTimer()
-
- for i := 0; i < b.N; i++ {
- _, err := p.ReadReply(m)
- if !wanterr && err != nil {
- b.Fatal(err)
- }
- }
-}
-
-func multiBulkParse(p *proto.Reader, n int64) (interface{}, error) {
- vv := make([]interface{}, 0, n)
- for i := int64(0); i < n; i++ {
- v, err := p.ReadReply(multiBulkParse)
- if err != nil {
- return nil, err
- }
- vv = append(vv, v)
- }
- return vv, nil
-}
diff --git a/vendor/github.com/go-redis/redis/internal/proto/scan.go b/vendor/github.com/go-redis/redis/internal/proto/scan.go
index 0329ffd99..3bdb33f9d 100644
--- a/vendor/github.com/go-redis/redis/internal/proto/scan.go
+++ b/vendor/github.com/go-redis/redis/internal/proto/scan.go
@@ -5,7 +5,7 @@ import (
"fmt"
"reflect"
- "github.com/go-redis/redis/internal"
+ "github.com/go-redis/redis/internal/util"
)
func Scan(b []byte, v interface{}) error {
@@ -13,80 +13,80 @@ func Scan(b []byte, v interface{}) error {
case nil:
return fmt.Errorf("redis: Scan(nil)")
case *string:
- *v = internal.BytesToString(b)
+ *v = util.BytesToString(b)
return nil
case *[]byte:
*v = b
return nil
case *int:
var err error
- *v, err = atoi(b)
+ *v, err = util.Atoi(b)
return err
case *int8:
- n, err := parseInt(b, 10, 8)
+ n, err := util.ParseInt(b, 10, 8)
if err != nil {
return err
}
*v = int8(n)
return nil
case *int16:
- n, err := parseInt(b, 10, 16)
+ n, err := util.ParseInt(b, 10, 16)
if err != nil {
return err
}
*v = int16(n)
return nil
case *int32:
- n, err := parseInt(b, 10, 32)
+ n, err := util.ParseInt(b, 10, 32)
if err != nil {
return err
}
*v = int32(n)
return nil
case *int64:
- n, err := parseInt(b, 10, 64)
+ n, err := util.ParseInt(b, 10, 64)
if err != nil {
return err
}
*v = n
return nil
case *uint:
- n, err := parseUint(b, 10, 64)
+ n, err := util.ParseUint(b, 10, 64)
if err != nil {
return err
}
*v = uint(n)
return nil
case *uint8:
- n, err := parseUint(b, 10, 8)
+ n, err := util.ParseUint(b, 10, 8)
if err != nil {
return err
}
*v = uint8(n)
return nil
case *uint16:
- n, err := parseUint(b, 10, 16)
+ n, err := util.ParseUint(b, 10, 16)
if err != nil {
return err
}
*v = uint16(n)
return nil
case *uint32:
- n, err := parseUint(b, 10, 32)
+ n, err := util.ParseUint(b, 10, 32)
if err != nil {
return err
}
*v = uint32(n)
return nil
case *uint64:
- n, err := parseUint(b, 10, 64)
+ n, err := util.ParseUint(b, 10, 64)
if err != nil {
return err
}
*v = n
return nil
case *float32:
- n, err := parseFloat(b, 32)
+ n, err := util.ParseFloat(b, 32)
if err != nil {
return err
}
@@ -94,7 +94,7 @@ func Scan(b []byte, v interface{}) error {
return err
case *float64:
var err error
- *v, err = parseFloat(b, 64)
+ *v, err = util.ParseFloat(b, 64)
return err
case *bool:
*v = len(b) == 1 && b[0] == '1'
@@ -120,7 +120,7 @@ func ScanSlice(data []string, slice interface{}) error {
return fmt.Errorf("redis: ScanSlice(non-slice %T)", slice)
}
- next := internal.MakeSliceNextElemFunc(v)
+ next := makeSliceNextElemFunc(v)
for i, s := range data {
elem := next()
if err := Scan([]byte(s), elem.Addr().Interface()); err != nil {
@@ -131,3 +131,36 @@ func ScanSlice(data []string, slice interface{}) error {
return nil
}
+
+func makeSliceNextElemFunc(v reflect.Value) func() reflect.Value {
+ elemType := v.Type().Elem()
+
+ if elemType.Kind() == reflect.Ptr {
+ elemType = elemType.Elem()
+ return func() reflect.Value {
+ if v.Len() < v.Cap() {
+ v.Set(v.Slice(0, v.Len()+1))
+ elem := v.Index(v.Len() - 1)
+ if elem.IsNil() {
+ elem.Set(reflect.New(elemType))
+ }
+ return elem.Elem()
+ }
+
+ elem := reflect.New(elemType)
+ v.Set(reflect.Append(v, elem))
+ return elem.Elem()
+ }
+ }
+
+ zero := reflect.Zero(elemType)
+ return func() reflect.Value {
+ if v.Len() < v.Cap() {
+ v.Set(v.Slice(0, v.Len()+1))
+ return v.Index(v.Len() - 1)
+ }
+
+ v.Set(reflect.Append(v, zero))
+ return v.Index(v.Len() - 1)
+ }
+}
diff --git a/vendor/github.com/go-redis/redis/internal/proto/scan_test.go b/vendor/github.com/go-redis/redis/internal/proto/scan_test.go
deleted file mode 100644
index fadcd0561..000000000
--- a/vendor/github.com/go-redis/redis/internal/proto/scan_test.go
+++ /dev/null
@@ -1,48 +0,0 @@
-package proto
-
-import (
- "encoding/json"
-
- . "github.com/onsi/ginkgo"
- . "github.com/onsi/gomega"
-)
-
-type testScanSliceStruct struct {
- ID int
- Name string
-}
-
-func (s *testScanSliceStruct) MarshalBinary() ([]byte, error) {
- return json.Marshal(s)
-}
-
-func (s *testScanSliceStruct) UnmarshalBinary(b []byte) error {
- return json.Unmarshal(b, s)
-}
-
-var _ = Describe("ScanSlice", func() {
- data := []string{
- `{"ID":-1,"Name":"Back Yu"}`,
- `{"ID":1,"Name":"szyhf"}`,
- }
-
- It("[]testScanSliceStruct", func() {
- var slice []testScanSliceStruct
- err := ScanSlice(data, &slice)
- Expect(err).NotTo(HaveOccurred())
- Expect(slice).To(Equal([]testScanSliceStruct{
- {-1, "Back Yu"},
- {1, "szyhf"},
- }))
- })
-
- It("var testContainer []*testScanSliceStruct", func() {
- var slice []*testScanSliceStruct
- err := ScanSlice(data, &slice)
- Expect(err).NotTo(HaveOccurred())
- Expect(slice).To(Equal([]*testScanSliceStruct{
- {-1, "Back Yu"},
- {1, "szyhf"},
- }))
- })
-})
diff --git a/vendor/github.com/go-redis/redis/internal/proto/write_buffer.go b/vendor/github.com/go-redis/redis/internal/proto/write_buffer.go
index 096b6d76a..cc4014fb4 100644
--- a/vendor/github.com/go-redis/redis/internal/proto/write_buffer.go
+++ b/vendor/github.com/go-redis/redis/internal/proto/write_buffer.go
@@ -71,17 +71,15 @@ func (w *WriteBuffer) append(val interface{}) error {
} else {
w.AppendString("0")
}
- default:
- if bm, ok := val.(encoding.BinaryMarshaler); ok {
- bb, err := bm.MarshalBinary()
- if err != nil {
- return err
- }
- w.AppendBytes(bb)
- } else {
- return fmt.Errorf(
- "redis: can't marshal %T (consider implementing encoding.BinaryMarshaler)", val)
+ case encoding.BinaryMarshaler:
+ b, err := v.MarshalBinary()
+ if err != nil {
+ return err
}
+ w.AppendBytes(b)
+ default:
+ return fmt.Errorf(
+ "redis: can't marshal %T (consider implementing encoding.BinaryMarshaler)", val)
}
return nil
}
diff --git a/vendor/github.com/go-redis/redis/internal/proto/write_buffer_test.go b/vendor/github.com/go-redis/redis/internal/proto/write_buffer_test.go
deleted file mode 100644
index 84799ff3b..000000000
--- a/vendor/github.com/go-redis/redis/internal/proto/write_buffer_test.go
+++ /dev/null
@@ -1,63 +0,0 @@
-package proto_test
-
-import (
- "testing"
- "time"
-
- "github.com/go-redis/redis/internal/proto"
-
- . "github.com/onsi/ginkgo"
- . "github.com/onsi/gomega"
-)
-
-var _ = Describe("WriteBuffer", func() {
- var buf *proto.WriteBuffer
-
- BeforeEach(func() {
- buf = proto.NewWriteBuffer()
- })
-
- It("should reset", func() {
- buf.AppendString("string")
- Expect(buf.Len()).To(Equal(12))
- buf.Reset()
- Expect(buf.Len()).To(Equal(0))
- })
-
- It("should append args", func() {
- err := buf.Append([]interface{}{
- "string",
- 12,
- 34.56,
- []byte{'b', 'y', 't', 'e', 's'},
- true,
- nil,
- })
- Expect(err).NotTo(HaveOccurred())
- Expect(buf.Bytes()).To(Equal([]byte("*6\r\n" +
- "$6\r\nstring\r\n" +
- "$2\r\n12\r\n" +
- "$5\r\n34.56\r\n" +
- "$5\r\nbytes\r\n" +
- "$1\r\n1\r\n" +
- "$0\r\n" +
- "\r\n")))
- })
-
- It("should append marshalable args", func() {
- err := buf.Append([]interface{}{time.Unix(1414141414, 0)})
- Expect(err).NotTo(HaveOccurred())
- Expect(buf.Len()).To(Equal(26))
- })
-
-})
-
-func BenchmarkWriteBuffer_Append(b *testing.B) {
- buf := proto.NewWriteBuffer()
- args := []interface{}{"hello", "world", "foo", "bar"}
-
- for i := 0; i < b.N; i++ {
- buf.Append(args)
- buf.Reset()
- }
-}
diff --git a/vendor/github.com/go-redis/redis/internal/singleflight/singleflight.go b/vendor/github.com/go-redis/redis/internal/singleflight/singleflight.go
new file mode 100644
index 000000000..3b1741724
--- /dev/null
+++ b/vendor/github.com/go-redis/redis/internal/singleflight/singleflight.go
@@ -0,0 +1,64 @@
+/*
+Copyright 2013 Google Inc.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+// Package singleflight provides a duplicate function call suppression
+// mechanism.
+package singleflight
+
+import "sync"
+
+// call is an in-flight or completed Do call
+type call struct {
+ wg sync.WaitGroup
+ val interface{}
+ err error
+}
+
+// Group represents a class of work and forms a namespace in which
+// units of work can be executed with duplicate suppression.
+type Group struct {
+ mu sync.Mutex // protects m
+ m map[string]*call // lazily initialized
+}
+
+// Do executes and returns the results of the given function, making
+// sure that only one execution is in-flight for a given key at a
+// time. If a duplicate comes in, the duplicate caller waits for the
+// original to complete and receives the same results.
+func (g *Group) Do(key string, fn func() (interface{}, error)) (interface{}, error) {
+ g.mu.Lock()
+ if g.m == nil {
+ g.m = make(map[string]*call)
+ }
+ if c, ok := g.m[key]; ok {
+ g.mu.Unlock()
+ c.wg.Wait()
+ return c.val, c.err
+ }
+ c := new(call)
+ c.wg.Add(1)
+ g.m[key] = c
+ g.mu.Unlock()
+
+ c.val, c.err = fn()
+ c.wg.Done()
+
+ g.mu.Lock()
+ delete(g.m, key)
+ g.mu.Unlock()
+
+ return c.val, c.err
+}
diff --git a/vendor/github.com/go-redis/redis/internal/util.go b/vendor/github.com/go-redis/redis/internal/util.go
index 1ba9805fe..ffd2353e0 100644
--- a/vendor/github.com/go-redis/redis/internal/util.go
+++ b/vendor/github.com/go-redis/redis/internal/util.go
@@ -1,6 +1,6 @@
package internal
-import "reflect"
+import "github.com/go-redis/redis/internal/util"
func ToLower(s string) string {
if isLower(s) {
@@ -15,7 +15,7 @@ func ToLower(s string) string {
}
b[i] = c
}
- return BytesToString(b)
+ return util.BytesToString(b)
}
func isLower(s string) bool {
@@ -27,36 +27,3 @@ func isLower(s string) bool {
}
return true
}
-
-func MakeSliceNextElemFunc(v reflect.Value) func() reflect.Value {
- elemType := v.Type().Elem()
-
- if elemType.Kind() == reflect.Ptr {
- elemType = elemType.Elem()
- return func() reflect.Value {
- if v.Len() < v.Cap() {
- v.Set(v.Slice(0, v.Len()+1))
- elem := v.Index(v.Len() - 1)
- if elem.IsNil() {
- elem.Set(reflect.New(elemType))
- }
- return elem.Elem()
- }
-
- elem := reflect.New(elemType)
- v.Set(reflect.Append(v, elem))
- return elem.Elem()
- }
- }
-
- zero := reflect.Zero(elemType)
- return func() reflect.Value {
- if v.Len() < v.Cap() {
- v.Set(v.Slice(0, v.Len()+1))
- return v.Index(v.Len() - 1)
- }
-
- v.Set(reflect.Append(v, zero))
- return v.Index(v.Len() - 1)
- }
-}
diff --git a/vendor/github.com/go-redis/redis/internal/safe.go b/vendor/github.com/go-redis/redis/internal/util/safe.go
index dc5f4cc8a..cd8918330 100644
--- a/vendor/github.com/go-redis/redis/internal/safe.go
+++ b/vendor/github.com/go-redis/redis/internal/util/safe.go
@@ -1,6 +1,6 @@
// +build appengine
-package internal
+package util
func BytesToString(b []byte) string {
return string(b)
diff --git a/vendor/github.com/go-redis/redis/internal/util/strconv.go b/vendor/github.com/go-redis/redis/internal/util/strconv.go
new file mode 100644
index 000000000..db5033802
--- /dev/null
+++ b/vendor/github.com/go-redis/redis/internal/util/strconv.go
@@ -0,0 +1,19 @@
+package util
+
+import "strconv"
+
+func Atoi(b []byte) (int, error) {
+ return strconv.Atoi(BytesToString(b))
+}
+
+func ParseInt(b []byte, base int, bitSize int) (int64, error) {
+ return strconv.ParseInt(BytesToString(b), base, bitSize)
+}
+
+func ParseUint(b []byte, base int, bitSize int) (uint64, error) {
+ return strconv.ParseUint(BytesToString(b), base, bitSize)
+}
+
+func ParseFloat(b []byte, bitSize int) (float64, error) {
+ return strconv.ParseFloat(BytesToString(b), bitSize)
+}
diff --git a/vendor/github.com/go-redis/redis/internal/unsafe.go b/vendor/github.com/go-redis/redis/internal/util/unsafe.go
index 3ae48c14b..93a89c55c 100644
--- a/vendor/github.com/go-redis/redis/internal/unsafe.go
+++ b/vendor/github.com/go-redis/redis/internal/util/unsafe.go
@@ -1,6 +1,6 @@
// +build !appengine
-package internal
+package util
import (
"unsafe"