Skip to content

Commit

Permalink
Merge pull request #40 from mna/wip-next
Browse files Browse the repository at this point in the history
v1.3.0
  • Loading branch information
mna authored Sep 4, 2021
2 parents 3e7287a + d827581 commit 13aabde
Show file tree
Hide file tree
Showing 22 changed files with 1,049 additions and 569 deletions.
12 changes: 0 additions & 12 deletions .builds/fedora.yml

This file was deleted.

47 changes: 47 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: test
on: [push, pull_request]

env:
GOPROXY: https://proxy.golang.org,direct

jobs:
test:
strategy:
matrix:
go-version: [1.15.x, 1.16.x, 1.17.x]
redis-version: [5.x, 6.x]
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}

steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

- name: Install Redis
uses: shogo82148/actions-setup-redis@v1
with:
redis-version: ${{ matrix.redis-version }}
auto-start: "false"

- name: Checkout code
uses: actions/checkout@v2

- name: Test
run: go test ./... -v -cover

- name: Data Race
run: go test ./... -race

golangci:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Lint
uses: golangci/golangci-lint-action@v2
with:
version: latest
57 changes: 57 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
linters:
disable-all: true
enable:
- deadcode
- errcheck
- gci
- gochecknoinits
- gofmt
- gosec
- gosimple
- govet
- importas
- ineffassign
- misspell
- nakedret
- prealloc
- revive
- staticcheck
- structcheck
- typecheck
- unconvert
- unparam
- unused
- varcheck

linters-settings:
revive:
ignoreGeneratedHeader: false
severity: "warning"
confidence: 0.8
errorCode: 0
warningCode: 0

rules:
- name: blank-imports
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: error-return
- name: error-strings
- name: error-naming
- name: exported
- name: increment-decrement
- name: var-naming
- name: var-declaration
- name: package-comments
- name: range
- name: receiver-naming
- name: time-naming
- name: unexported-return
- name: indent-error-flow
- name: errorf
- name: empty-block
- name: superfluous-else
- name: unused-parameter
- name: unreachable-code
- name: redefines-builtin-id
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# redisc [![Go Reference](https://pkg.go.dev/badge/github.com/mna/redisc.svg)](https://pkg.go.dev/github.com/mna/redisc) [![builds.sr.ht status](https://builds.sr.ht/~mna/redisc.svg)](https://builds.sr.ht/~mna/redisc?)
[![Go Reference](https://pkg.go.dev/badge/github.com/mna/redisc.svg)](https://pkg.go.dev/github.com/mna/redisc)
[![Build Status](https://github.com/mna/redisc/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/mna/redisc/actions)

# redisc

Package redisc implements a redis cluster client built on top of the [redigo package][redigo]. See the [documentation][godoc] for details.

Expand All @@ -8,6 +11,8 @@ Package redisc implements a redis cluster client built on top of the [redigo pac

## Releases

* **v1.3.0** : Add `Cluster.EachNode` to call a function with a connection for each known node in the cluster (e.g. to run diagnostics commands on each node or to collect all keys in a cluster); add optional Cluster function field `BgError` to receive notification of errors happening in background topology refreshes and on closing of `RetryConn` after following a redirection to a new connection; add optional Cluster function field `LayoutRefresh` to receive the old and new cluster slot mappings to server address(es); prevent unnecessary cluster layout refreshes when the internal mapping is the same as the redirection error; better handling of closed Cluster; move CI to Github Actions; drop support for old Go versions (currently tested on 1.15+); enable more static analysis/linters; refactor tests to create less separate clusters and run faster.

* **v1.2.0** : Use Go modules, fix a failing test due to changed error message on Redis 6.

* **v1.1.7** : Do not bind to a random node if `Do` is called without a command and the connection is not already bound (thanks to [@tysonmote][tysonmote]).
Expand All @@ -32,13 +37,13 @@ Package redisc implements a redis cluster client built on top of the [redigo pac

The [code documentation][godoc] is the canonical source for documentation.

The design goal of redisc is to be as compatible as possible with the [redigo][] package. As such, the `Cluster` type can be used as a drop-in replacement to a `redis.Pool`, and the connections returned by the cluster implement the `redis.Conn` interface. The package offers additional features specific to dealing with a cluster that may be needed for more advanced scenarios.
The design goal of redisc is to be as compatible as possible with the [redigo][] package. As such, the `Cluster` type can be used as a drop-in replacement to a `redis.Pool` when moving from a standalone Redis to a Redis Cluster setup, and the connections returned by the cluster implement redigo's `redis.Conn` interface. The package offers additional features specific to dealing with a cluster that may be needed for more advanced scenarios.

The main features are:

* Drop-in replacement for `redis.Pool` (the `Cluster` type implements the same `Get` and `Close` method signatures).
* Connections are `redis.Conn` interfaces and use the `redigo` package to execute commands, `redisc` only handles the cluster part.
* Support for all cluster-supported commands including scripting, transactions and pub-sub.
* Support for all cluster-supported commands including scripting, transactions and pub-sub (within the limitations imposed by Redis Cluster).
* Support for READONLY/READWRITE commands to allow reading data from replicas.
* Client-side smart routing, automatically keeps track of which node holds which key slots.
* Automatic retry of MOVED, ASK and TRYAGAIN errors when desired, via `RetryConn`.
Expand All @@ -47,6 +52,8 @@ The main features are:
* Explicit selection of the node to call via `BindConn` when needed.
* Support for optimal batch calls via `SplitBySlot`.

Note that to make efficient use of Redis Cluster, some upfront work is usually required. A good understanding of Redis Cluster is highly recommended and the official Redis website has [good documentation that covers this](https://redis.io/topics/cluster-spec). In particular, [Migrating to Redis Cluster](https://redis.io/topics/cluster-tutorial#migrating-to-redis-cluster) will help understand how straightforward (or not) the migration may be for your specific case.

## Alternatives

* [redis-go-cluster][rgc].
Expand All @@ -65,9 +72,6 @@ There are a number of ways you can support the project:
- Be mindful of existing code - PRs that break existing code have a high probability of being declined, unless it fixes a serious issue.
* Sponsor the developer
- See the Github Sponsor button at the top of the repo on github
- or via BuyMeACoffee.com, below

<a href="https://www.buymeacoffee.com/mna" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: 41px !important;width: 174px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;" ></a>

## License

Expand Down
3 changes: 2 additions & 1 deletion ccheck/ccheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,11 @@ func printStats() {

func genKey() string {
ks := workingSet
//nolint:gosec
if rand.Float64() > 0.5 {
ks = keySpace
}
return "key_" + strconv.Itoa(rand.Intn(ks))
return "key_" + strconv.Itoa(rand.Intn(ks)) //nolint:gosec
}

func createPool(addr string, opts ...redis.DialOption) (*redis.Pool, error) {
Expand Down
Loading

0 comments on commit 13aabde

Please sign in to comment.