Skip to content

Commit

Permalink
document new ConnWithTimeout support
Browse files Browse the repository at this point in the history
  • Loading branch information
mna committed Jan 27, 2019
1 parent c50b367 commit 037b19b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Package redisc implements a redis cluster client built on top of the [redigo pac

## Releases

* **v1.1.4** : Add `Conn.DoWithTimeout` and `Conn.ReceiveWithTimeout` to match redigo's `ConnWithTimeout` interface (thanks to [@letsfire][letsfire]).

* **v1.1.3** : Fix handling of `ASK` replies in `RetryConn`.

* **v1.1.2** : Remove mention that `StartupNodes` in `Cluster` struct needs to be master nodes (it can be replicas). Add supporting test.
Expand Down Expand Up @@ -69,4 +71,4 @@ The [BSD 3-Clause license][bsd].
[rgc]: https://github.com/chasex/redis-go-cluster
[radix1]: https://github.com/fzzy/radix
[radix2]: https://github.com/mediocregopher/radix.v2

[letsfire]: https://github.com/letsfire
19 changes: 13 additions & 6 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/gomodule/redigo/redis"
)

var _ redis.Conn = (*Conn)(nil)
var _ redis.ConnWithTimeout = (*Conn)(nil)

// Conn is a redis cluster connection. When returned by Get
// or Dial, it is not yet bound to any node in the cluster.
Expand Down Expand Up @@ -236,9 +236,12 @@ func (c *Conn) Do(cmd string, args ...interface{}) (interface{}, error) {
return c.DoWithTimeout(-1, cmd, args...)
}

// Do sends a command to the server and returns the received reply.
// The timeout overrides the write timeout set when dialing the
// connection.
// DoWithTimeout sends a command to the server and returns the received reply.
// If the connection is not yet bound to a cluster node, it will be
// after this call, based on the rules documented in the Conn type.
//
// The timeout overrides the read timeout set when dialing the
// connection (in the DialOptions of the Cluster).
func (c *Conn) DoWithTimeout(timeout time.Duration, cmd string, args ...interface{}) (v interface{}, err error) {
rc, _, err := c.bind(cmdSlot(cmd, args))
if err != nil {
Expand Down Expand Up @@ -278,8 +281,12 @@ func (c *Conn) Receive() (interface{}, error) {
return c.ReceiveWithTimeout(-1)
}

// Receive receives a single reply from the Redis server. The timeout
// overrides the read timeout set when dialing the connection.
// ReceiveWithTimeout receives a single reply from the Redis server.
// If the connection is not yet bound to a cluster node, it will be
// after this call, based on the rules documented in the Conn type.
//
// The timeout overrides the read timeout set when dialing the
// connection (in the DialOptions of the Cluster).
func (c *Conn) ReceiveWithTimeout(timeout time.Duration) (v interface{}, err error) {
rc, _, err := c.bind(-1)
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
// for a redis.Pool from the redigo package.
//
// Similarly, the Conn type implements redigo's redis.Conn
// interface, so the API to execute commands is the same -
// interface (and the augmented redis.ConnWithTimeout one too),
// so the API to execute commands is the same -
// in fact the redisc package uses the redigo package as its
// only third-party dependency.
//
Expand Down Expand Up @@ -83,7 +84,8 @@
// Connection
//
// The connection returned from Get or Dial is a redigo redis.Conn
// interface, with a concrete type of *Conn. In addition to the
// interface (that also implements redis.ConnWithTimeout),
// with a concrete type of *Conn. In addition to the
// interface's required methods, *Conn adds the following methods:
//
// Bind(...string) error
Expand Down

0 comments on commit 037b19b

Please sign in to comment.