Skip to content

Commit

Permalink
Fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mna committed Oct 12, 2023
1 parent 871ec66 commit 5a34ab7
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 50 deletions.
3 changes: 0 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
linters:
disable-all: true
enable:
- deadcode
- errcheck
- gci
- gochecknoinits
Expand All @@ -16,12 +15,10 @@ linters:
- prealloc
- revive
- staticcheck
- structcheck
- typecheck
- unconvert
- unparam
- unused
- varcheck

linters-settings:
revive:
Expand Down
18 changes: 9 additions & 9 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ var _ redis.ConnWithTimeout = (*Conn)(nil)
// yet bound to any node in the cluster. Only when a call to Do, Send, Receive
// or Bind is made is a connection to a specific node established:
//
// - if Do or Send is called first, the command's first parameter is
// - if Do or Send is called first, the command's first parameter is
// assumed to be the key, and its slot is used to find the node
// - if Receive is called first, or if Do or Send is called first but with
// - if Receive is called first, or if Do or Send is called first but with
// no parameter for the command (or no command), a random node is selected
// in the cluster
// - if Bind is called first, the node corresponding to the slot of the
// - if Bind is called first, the node corresponding to the slot of the
// specified key(s) is selected
//
// Because Get and Dial return a redis.Conn interface, a type assertion can be
// used to call Bind or ReadOnly on this concrete Conn type:
//
// redisConn := cluster.Get()
// if conn, ok := redisConn.(*redisc.Conn); ok {
// if err := conn.Bind("my-key"); err != nil {
// // handle error
// }
// }
// redisConn := cluster.Get()
// if conn, ok := redisConn.(*redisc.Conn); ok {
// if err := conn.Bind("my-key"); err != nil {
// // handle error
// }
// }
//
// Alternatively, the package-level BindConn or ReadOnlyConn helper functions
// may be used.
Expand Down
67 changes: 33 additions & 34 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// read-only connections to read data from replicas.
// See http://redis.io/topics/cluster-spec for details.
//
// Design
// # Design
//
// The package defines two main types: Cluster and Conn. Both
// are described in more details below, but the Cluster manages
Expand All @@ -26,40 +26,40 @@
// When more control is needed, the package offers some
// extra behaviour specific to working with a redis cluster:
//
// - Slot and SplitBySlot functions to compute the slot for
// - Slot and SplitBySlot functions to compute the slot for
// a given key and to split a list of keys into groups of
// keys from the same slot, so that each group can safely be
// handled using the same connection.
//
// - *Conn.Bind (or the BindConn package-level helper function)
// - *Conn.Bind (or the BindConn package-level helper function)
// to explicitly specify the keys that will be used with the
// connection so that the right node is selected, instead of
// relying on the automatic detection based on the first
// parameter of the command.
//
// - *Conn.ReadOnly (or the ReadOnlyConn package-level helper
// - *Conn.ReadOnly (or the ReadOnlyConn package-level helper
// function) to mark a connection as read-only, allowing
// commands to be served by a replica instead of the master.
//
// - RetryConn to wrap a connection into one that automatically
// - RetryConn to wrap a connection into one that automatically
// follows redirections when the cluster moves slots around.
//
// - Helper functions to deal with cluster-specific errors.
// - Helper functions to deal with cluster-specific errors.
//
// Cluster
// # Cluster
//
// The Cluster type manages a redis cluster and offers an
// interface compatible with redigo's redis.Pool:
//
// Get() redis.Conn
// Close() error
// Get() redis.Conn
// Close() error
//
// Along with some additional methods specific to a cluster:
//
// Dial() (redis.Conn, error)
// EachNode(bool, func(string, redis.Conn) error) error
// Refresh() error
// Stats() map[string]redis.PoolStats
// Dial() (redis.Conn, error)
// EachNode(bool, func(string, redis.Conn) error) error
// Refresh() error
// Stats() map[string]redis.PoolStats
//
// If the CreatePool function field is set, then a
// redis.Pool is created to manage connections to each of the
Expand Down Expand Up @@ -91,15 +91,15 @@
// A cluster must be closed once it is no longer used to release
// its resources.
//
// Connection
// # Connection
//
// The connection returned from Get or Dial is a redigo redis.Conn
// 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
// ReadOnly() error
// Bind(...string) error
// ReadOnly() error
//
// The returned connection is not yet connected to any node; it is
// "bound" to a specific node only when a call to Do, Send, Receive
Expand All @@ -121,12 +121,12 @@
// type assertion must be used to access the underlying *Conn and
// to be able to call Bind:
//
// redisConn := cluster.Get()
// if conn, ok := redisConn.(*redisc.Conn); ok {
// if err := conn.Bind("my-key"); err != nil {
// // handle error
// }
// }
// redisConn := cluster.Get()
// if conn, ok := redisConn.(*redisc.Conn); ok {
// if err := conn.Bind("my-key"); err != nil {
// // handle error
// }
// }
//
// The BindConn package-level function is provided as a helper for
// this common use-case.
Expand All @@ -151,7 +151,7 @@
// The connection must be closed after use, to release the underlying
// resources.
//
// Redirections
// # Redirections
//
// The redis cluster may return MOVED and ASK errors when the node
// that received the command doesn't currently hold the slot corresponding
Expand All @@ -169,22 +169,21 @@
// its mapping of slots to nodes automatically by keeping track of
// MOVED replies.
//
// Concurrency
// # Concurrency
//
// The concurrency model is similar to that of the redigo package:
//
// - Cluster methods are safe to call concurrently (like redis.Pool).
// - Cluster methods are safe to call concurrently (like redis.Pool).
//
// - Connections do not support concurrent calls to write methods
// (Send, Flush) or concurrent calls to the read method (Receive).
// - Connections do not support concurrent calls to write methods
// (Send, Flush) or concurrent calls to the read method (Receive).
//
// - Connections do allow a concurrent reader and writer.
// - Connections do allow a concurrent reader and writer.
//
// - Because the Do method combines the functionality of Send, Flush
// and Receive, it cannot be called concurrently with other methods.
//
// - The Bind and ReadOnly methods are safe to call concurrently, but
// there is not much point in doing so for as both will fail if
// the connection is already bound.
// - Because the Do method combines the functionality of Send, Flush
// and Receive, it cannot be called concurrently with other methods.
//
// - The Bind and ReadOnly methods are safe to call concurrently, but
// there is not much point in doing so for as both will fail if
// the connection is already bound.
package redisc
8 changes: 4 additions & 4 deletions hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ func Slot(key string) int {
// SplitBySlot takes a list of keys and returns a list of list of keys,
// grouped by identical cluster slot. For example:
//
// bySlot := SplitBySlot("k1", "k2", "k3")
// for _, keys := range bySlot {
// // keys is a list of keys that belong to the same slot
// }
// bySlot := SplitBySlot("k1", "k2", "k3")
// for _, keys := range bySlot {
// // keys is a list of keys that belong to the same slot
// }
func SplitBySlot(keys ...string) [][]string {
var slots []int
m := make(map[int][]string)
Expand Down

0 comments on commit 5a34ab7

Please sign in to comment.