Skip to content

Commit

Permalink
Update Redis client
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcook committed Feb 23, 2023
1 parent 3bc8259 commit 7c5cfc5
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 43 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"fmt"
"sync"

"github.com/go-redis/redis/v8"
"github.com/redis/go-redis/v9"
"github.com/nytimes/grocery"
)

Expand Down
19 changes: 19 additions & 0 deletions bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,25 @@ func TestCustomMapType(t *testing.T) {
}
}

func TestUnexported(t *testing.T) {
data := map[string]string{
"us": "unexported",
}

ptr := new(bindTestStruct)
err := bind("", "", data, ptr)

if err != nil {
t.Errorf("unexported FAILED, got error %v", err)
}

if ptr.unexported == "" {
t.Log("unexported PASSED")
} else {
t.Errorf("unexported FAILED, expected %v but got %v", "", ptr.unexported)
}
}

func TestTimestamp(t *testing.T) {
data := map[string]string{
"t": "963210120",
Expand Down
2 changes: 1 addition & 1 deletion connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"sync"
"time"

"github.com/go-redis/redis/v8"
"github.com/redis/go-redis/v9"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions custom_bool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package grocery
import (
"testing"

"github.com/go-redis/redis/v8"
"github.com/redis/go-redis/v9"
)

type ZContains bool
Expand Down Expand Up @@ -36,7 +36,7 @@ func TestZContains(t *testing.T) {
t.Error(err)
}

C.ZAdd(ctx, "sortedSetTest", &redis.Z{Score: 1, Member: id}).Result()
C.ZAdd(ctx, "sortedSetTest", redis.Z{Score: 1, Member: id}).Result()

loadedModel := new(ZContainsTestModel)
err = Load(id, loadedModel)
Expand Down
2 changes: 1 addition & 1 deletion docs/demo.go.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

"github.com/fatih/color"
"github.com/go-redis/redis/v8"
"github.com/redis/go-redis/v9"
"github.com/nytimes/grocery"
)

Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ <h2>
"fmt"
"sync"

"github.com/go-redis/redis/v8"
"github.com/redis/go-redis/v9"
"github.com/nytimes/grocery"
)

Expand Down
6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ module github.com/nytimes/grocery
go 1.18

require (
github.com/go-redis/redis/v8 v8.11.5
github.com/google/uuid v1.3.0
github.com/redis/go-redis/v9 v9.0.2
)

require (
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
golang.org/x/net v0.0.0-20220420153159-1850ba15e1be // indirect
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
)
25 changes: 10 additions & 15 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/bsm/ginkgo/v2 v2.5.0 h1:aOAnND1T40wEdAtkGSkvSICWeQ8L3UASX7YVCqQx+eQ=
github.com/bsm/gomega v1.20.0 h1:JhAwLmtRzXFTx2AkALSLa8ijZafntmhSoU63Ok18Uq8=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
golang.org/x/net v0.0.0-20220420153159-1850ba15e1be h1:yx80W7nvY5ySWpaU8UWaj5o9e23YgO9BRhQol7Lc+JI=
golang.org/x/net v0.0.0-20220420153159-1850ba15e1be/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/redis/go-redis/v9 v9.0.2 h1:BA426Zqe/7r56kCcvxYLWe1mkaz71LKF77GwgFzSxfE=
github.com/redis/go-redis/v9 v9.0.2/go.mod h1:/xDTe9EF1LM61hek62Poq2nzQSGj0xSrEtEHbBQevps=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
4 changes: 2 additions & 2 deletions load.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"reflect"
"strings"

"github.com/go-redis/redis/v8"
"github.com/redis/go-redis/v9"
)

// Load automates the process of loading data from Redis, binding it to a
Expand Down Expand Up @@ -69,7 +69,7 @@ func LoadAll[T any](ids []string, values *[]T) error {

// Pipeline all HGetAll commands
pip := C.Pipeline()
cmds := make([]*redis.StringStringMapCmd, len(ids))
cmds := make([]*redis.MapStringStringCmd, len(ids))

for i, id := range ids {
cmds[i] = pip.HGetAll(ctx, prefix+":"+id)
Expand Down
2 changes: 1 addition & 1 deletion model_hook.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package grocery

import "github.com/go-redis/redis/v8"
import "github.com/redis/go-redis/v9"

// ModelHook provides hooks that structs may implement if you would like to
// receive callbacks on certain events.
Expand Down
39 changes: 25 additions & 14 deletions test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package grocery

import (
"context"
"net"
"os"
"testing"

"github.com/go-redis/redis/v8"
"github.com/redis/go-redis/v9"
)

var keys = map[string]bool{}
Expand Down Expand Up @@ -38,23 +39,33 @@ func TestMain(m *testing.M) {
// Hooks used to save keys stored during tests so we can delete them once tests complete
type testHook struct{}

func (testHook) BeforeProcess(ctx context.Context, cmd redis.Cmder) (context.Context, error) {
return ctx, nil
}

func (testHook) AfterProcess(ctx context.Context, cmd redis.Cmder) error {
keys[cmd.Args()[1].(string)] = true
return nil
func (testHook) DialHook(next redis.DialHook) redis.DialHook {
return func(ctx context.Context, network, addr string) (net.Conn, error) {
return next(ctx, network, addr)
}
}

func (testHook) BeforeProcessPipeline(ctx context.Context, cmds []redis.Cmder) (context.Context, error) {
return ctx, nil
}
func (testHook) ProcessHook(next redis.ProcessHook) redis.ProcessHook {
return func(ctx context.Context, cmd redis.Cmder) error {
if err := next(ctx, cmd); err != nil {
return err
}

func (testHook) AfterProcessPipeline(ctx context.Context, cmds []redis.Cmder) error {
for _, cmd := range cmds {
keys[cmd.Args()[1].(string)] = true
return nil
}
}

func (testHook) ProcessPipelineHook(next redis.ProcessPipelineHook) redis.ProcessPipelineHook {
return func(ctx context.Context, cmds []redis.Cmder) error {
if err := next(ctx, cmds); err != nil {
return err
}

return nil
for _, cmd := range cmds {
keys[cmd.Args()[1].(string)] = true
}

return nil
}
}
2 changes: 1 addition & 1 deletion update.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
"time"

"github.com/go-redis/redis/v8"
"github.com/redis/go-redis/v9"
)

// UpdateOptions provides options that may be passed to UpdateWithOptions if
Expand Down

0 comments on commit 7c5cfc5

Please sign in to comment.