소스 검색

Restore support for Go 1.4 - Go 1.6

Gary Burd 7 년 전
부모
커밋
a69d193512
5개의 변경된 파일100개의 추가작업 그리고 53개의 파일을 삭제
  1. 3 0
      .travis.yml
  2. 4 18
      redis/pool.go
  3. 35 0
      redis/pool17.go
  4. 58 0
      redis/pool17_test.go
  5. 0 35
      redis/pool_test.go

+ 3 - 0
.travis.yml

@@ -4,6 +4,9 @@ services:
   - redis-server
 
 go:
+  - 1.4
+  - 1.5.x
+  - 1.6.x
   - 1.7.x
   - 1.8.x
   - 1.9.x

+ 4 - 18
redis/pool.go

@@ -16,7 +16,6 @@ package redis
 
 import (
 	"bytes"
-	"context"
 	"crypto/rand"
 	"crypto/sha1"
 	"errors"
@@ -180,22 +179,6 @@ func (p *Pool) Get() Conn {
 	return &pooledConnection{p: p, c: c}
 }
 
-// GetContext gets a connection using the provided context.
-//
-// The provided Context must be non-nil. If the context expires before the
-// connection is complete, an error is returned. Any expiration on the context
-// will not affect the returned connection.
-//
-// If the function completes without error, then the application must close the
-// returned connection.
-func (p *Pool) GetContext(ctx context.Context) (Conn, error) {
-	c, err := p.get(ctx)
-	if err != nil {
-		return errorConnection{err}, err
-	}
-	return &pooledConnection{p: p, c: c}, nil
-}
-
 // PoolStats contains pool statistics.
 type PoolStats struct {
 	// ActiveCount is the number of connections in the pool. The count includes
@@ -279,7 +262,10 @@ func (p *Pool) lazyInit() {
 
 // get prunes stale connections and returns a connection from the idle list or
 // creates a new connection.
-func (p *Pool) get(ctx context.Context) (Conn, error) {
+func (p *Pool) get(ctx interface {
+	Done() <-chan struct{}
+	Err() error
+}) (Conn, error) {
 
 	// Handle limit for p.Wait == true.
 	if p.Wait && p.MaxActive > 0 {

+ 35 - 0
redis/pool17.go

@@ -0,0 +1,35 @@
+// Copyright 2018 Gary Burd
+//
+// 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.
+
+// +build go1.7
+
+package redis
+
+import "context"
+
+// GetContext gets a connection using the provided context.
+//
+// The provided Context must be non-nil. If the context expires before the
+// connection is complete, an error is returned. Any expiration on the context
+// will not affect the returned connection.
+//
+// If the function completes without error, then the application must close the
+// returned connection.
+func (p *Pool) GetContext(ctx context.Context) (Conn, error) {
+	c, err := p.get(ctx)
+	if err != nil {
+		return errorConnection{err}, err
+	}
+	return &pooledConnection{p: p, c: c}, nil
+}

+ 58 - 0
redis/pool17_test.go

@@ -0,0 +1,58 @@
+// Copyright 2018 Gary Burd
+//
+// 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.
+
+// +build go1.7
+
+package redis_test
+
+import (
+	"context"
+	"testing"
+
+	"github.com/garyburd/redigo/redis"
+)
+
+func TestWaitPoolGetAfterClose(t *testing.T) {
+	d := poolDialer{t: t}
+	p := &redis.Pool{
+		MaxIdle:   1,
+		MaxActive: 1,
+		Dial:      d.dial,
+		Wait:      true,
+	}
+	p.Close()
+	_, err := p.GetContext(context.Background())
+	if err == nil {
+		t.Fatal("expected error")
+	}
+}
+
+func TestWaitPoolGetCanceledContext(t *testing.T) {
+	d := poolDialer{t: t}
+	p := &redis.Pool{
+		MaxIdle:   1,
+		MaxActive: 1,
+		Dial:      d.dial,
+		Wait:      true,
+	}
+	defer p.Close()
+	ctx, f := context.WithCancel(context.Background())
+	f()
+	c := p.Get()
+	defer c.Close()
+	_, err := p.GetContext(ctx)
+	if err != context.Canceled {
+		t.Fatalf("got error %v, want %v", err, context.Canceled)
+	}
+}

+ 0 - 35
redis/pool_test.go

@@ -15,7 +15,6 @@
 package redis_test
 
 import (
-	"context"
 	"errors"
 	"io"
 	"reflect"
@@ -586,40 +585,6 @@ func TestWaitPoolDialError(t *testing.T) {
 	d.check("done", p, cap(errs), 0, 0)
 }
 
-func TestWaitPoolGetAfterClose(t *testing.T) {
-	d := poolDialer{t: t}
-	p := &redis.Pool{
-		MaxIdle:   1,
-		MaxActive: 1,
-		Dial:      d.dial,
-		Wait:      true,
-	}
-	p.Close()
-	_, err := p.GetContext(context.Background())
-	if err == nil {
-		t.Fatal("expected error")
-	}
-}
-
-func TestWaitPoolGetCanceledContext(t *testing.T) {
-	d := poolDialer{t: t}
-	p := &redis.Pool{
-		MaxIdle:   1,
-		MaxActive: 1,
-		Dial:      d.dial,
-		Wait:      true,
-	}
-	defer p.Close()
-	ctx, f := context.WithCancel(context.Background())
-	f()
-	c := p.Get()
-	defer c.Close()
-	_, err := p.GetContext(ctx)
-	if err != context.Canceled {
-		t.Fatalf("got error %v, want %v", err, context.Canceled)
-	}
-}
-
 // Borrowing requires us to iterate over the idle connections, unlock the pool,
 // and perform a blocking operation to check the connection still works. If
 // TestOnBorrow fails, we must reacquire the lock and continue iteration. This