Merge branch 'master' into master

This commit is contained in:
cong 2024-01-02 16:29:56 +08:00 committed by GitHub
commit cb82d303ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
54 changed files with 2102 additions and 229 deletions

1
.github/CODEOWNERS vendored Normal file
View File

@ -0,0 +1 @@
doctests/* @dmaier-redislabs

View File

@ -28,7 +28,7 @@ jobs:
steps:
- name: Set up ${{ matrix.go-version }}
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

View File

@ -29,7 +29,7 @@ jobs:
steps:
- name: Set up ${{ matrix.go-version }}
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

View File

@ -8,7 +8,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Check Spelling
uses: rojopolis/spellcheck-github-actions@0.33.1
uses: rojopolis/spellcheck-github-actions@0.35.0
with:
config_path: .github/spellcheck-settings.yml
task_name: Markdown

View File

@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v8
- uses: actions/stale@v9
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'This issue is marked stale. It will be closed in 30 days if it is not updated.'

View File

@ -0,0 +1,59 @@
name: RE Tests
on:
push:
branches: [master]
pull_request:
permissions:
contents: read
jobs:
build:
name: build
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
go-version: [1.21.x]
re-build: ["7.2.4-92"]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Clone Redis EE docker repository
uses: actions/checkout@v4
with:
repository: RedisLabs/redis-ee-docker
path: redis-ee
- name: Set up ${{ matrix.go-version }}
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Build cluster
working-directory: redis-ee
env:
IMAGE: "redislabs/redis-internal:${{ matrix.re-build }}"
RE_USERNAME: ${{ secrets.RE_USERNAME }}
RE_PASS: ${{ secrets.RE_PASS }}
RE_CLUSTER_NAME: ${{ secrets.RE_CLUSTER_NAME }}
OSS_CLUSTER: false
DB_PORT: ${{ secrets.RE_DB_PORT }}
DOCKER_ACCESS_TOKEN: ${{ secrets.DOCKER_ACCESS_TOKEN }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
run: ./build.sh
- name: Test
env:
RE_CLUSTER: "1"
run: |
go test \
--ginkgo.skip-file="ring_test.go" \
--ginkgo.skip-file="sentinel_test.go" \
--ginkgo.skip-file="osscluster_test.go" \
--ginkgo.skip-file="pubsub_test.go" \
--ginkgo.skip-file="gears_commands_test.go" \
--ginkgo.label-filter='!NonRedisEnterprise'

View File

@ -13,6 +13,20 @@
> See [OpenTelemetry](https://github.com/redis/go-redis/tree/master/example/otel) example which
> demonstrates how you can use Uptrace to monitor go-redis.
## How do I Redis?
[Learn for free at Redis University](https://university.redis.com/)
[Build faster with the Redis Launchpad](https://launchpad.redis.com/)
[Try the Redis Cloud](https://redis.com/try-free/)
[Dive in developer tutorials](https://developer.redis.com/)
[Join the Redis community](https://redis.com/community/)
[Work at Redis](https://redis.com/company/careers/jobs/)
## Documentation
- [English](https://redis.uptrace.dev)
@ -135,15 +149,16 @@ import (
"github.com/redis/go-redis/v9"
)
var ctx = context.Background()
func ExampleClient() {
url := "redis://localhost:6379?password=hello&protocol=3"
func ExampleClient() *redis.Client {
url := "redis://user:password@localhost:6379/0?protocol=3"
opts, err := redis.ParseURL(url)
if err != nil {
panic(err)
}
rdb := redis.NewClient(opts)
return redis.NewClient(opts)
}
```
## Contributing

View File

@ -59,14 +59,6 @@ func NewClusterClientStub(resp []byte) *ClientStub {
},
})
// init command.
tmpClient := NewClient(&Options{Addr: ":6379"})
cmdsInfo, err := tmpClient.Command(ctx).Result()
_ = tmpClient.Close()
client.cmdsInfoCache = newCmdsInfoCache(func(_ context.Context) (map[string]*CommandInfo, error) {
return cmdsInfo, err
})
stub.Cmdable = client
return stub
}

View File

@ -1,6 +1,8 @@
package redis
import "context"
import (
"context"
)
type BitMapCmdable interface {
GetBit(ctx context.Context, key string, offset int64) *IntCmd
@ -127,3 +129,21 @@ func (c cmdable) BitField(ctx context.Context, key string, values ...interface{}
_ = c(ctx, cmd)
return cmd
}
// BitFieldRO - Read-only variant of the BITFIELD command.
// It is like the original BITFIELD but only accepts GET subcommand and can safely be used in read-only replicas.
// - BitFieldRO(ctx, key, "<Encoding0>", "<Offset0>", "<Encoding1>","<Offset1>")
func (c cmdable) BitFieldRO(ctx context.Context, key string, values ...interface{}) *IntSliceCmd {
args := make([]interface{}, 2, 2+len(values))
args[0] = "BITFIELD_RO"
args[1] = key
if len(values)%2 != 0 {
panic("BitFieldRO: invalid number of arguments, must be even")
}
for i := 0; i < len(values); i += 2 {
args = append(args, "GET", values[i], values[i+1])
}
cmd := NewIntSliceCmd(ctx, args...)
_ = c(ctx, cmd)
return cmd
}

View File

@ -1,11 +1,14 @@
package redis
import (
"bufio"
"context"
"fmt"
"net"
"regexp"
"strconv"
"strings"
"sync"
"time"
"github.com/redis/go-redis/v9/internal"
@ -15,10 +18,22 @@ import (
)
type Cmder interface {
// command name.
// e.g. "set k v ex 10" -> "set", "cluster info" -> "cluster".
Name() string
// full command name.
// e.g. "set k v ex 10" -> "set", "cluster info" -> "cluster info".
FullName() string
// all args of the command.
// e.g. "set k v ex 10" -> "[set k v ex 10]".
Args() []interface{}
// format request and response string.
// e.g. "set k v ex 10" -> "set k v ex 10: OK", "get k" -> "get k: v".
String() string
stringArg(int) string
firstKeyPos() int8
SetFirstKeyPos(int8)
@ -60,7 +75,7 @@ func writeCmd(wr *proto.Writer, cmd Cmder) error {
return wr.WriteArgs(cmd.Args())
}
func cmdFirstKeyPos(cmd Cmder, info *CommandInfo) int {
func cmdFirstKeyPos(cmd Cmder) int {
if pos := cmd.firstKeyPos(); pos != 0 {
return int(pos)
}
@ -80,10 +95,6 @@ func cmdFirstKeyPos(cmd Cmder, info *CommandInfo) int {
return 2
}
}
if info != nil {
return int(info.FirstKeyPos)
}
return 1
}
@ -5298,3 +5309,165 @@ type LibraryInfo struct {
LibName *string
LibVer *string
}
// -------------------------------------------
type InfoCmd struct {
baseCmd
val map[string]map[string]string
}
var _ Cmder = (*InfoCmd)(nil)
func NewInfoCmd(ctx context.Context, args ...interface{}) *InfoCmd {
return &InfoCmd{
baseCmd: baseCmd{
ctx: ctx,
args: args,
},
}
}
func (cmd *InfoCmd) SetVal(val map[string]map[string]string) {
cmd.val = val
}
func (cmd *InfoCmd) Val() map[string]map[string]string {
return cmd.val
}
func (cmd *InfoCmd) Result() (map[string]map[string]string, error) {
return cmd.Val(), cmd.Err()
}
func (cmd *InfoCmd) String() string {
return cmdString(cmd, cmd.val)
}
func (cmd *InfoCmd) readReply(rd *proto.Reader) error {
val, err := rd.ReadString()
if err != nil {
return err
}
section := ""
scanner := bufio.NewScanner(strings.NewReader(val))
moduleRe := regexp.MustCompile(`module:name=(.+?),(.+)$`)
for scanner.Scan() {
line := scanner.Text()
if strings.HasPrefix(line, "#") {
if cmd.val == nil {
cmd.val = make(map[string]map[string]string)
}
section = strings.TrimPrefix(line, "# ")
cmd.val[section] = make(map[string]string)
} else if line != "" {
if section == "Modules" {
kv := moduleRe.FindStringSubmatch(line)
if len(kv) == 3 {
cmd.val[section][kv[1]] = kv[2]
}
} else {
kv := strings.SplitN(line, ":", 2)
if len(kv) == 2 {
cmd.val[section][kv[0]] = kv[1]
}
}
}
}
return nil
}
func (cmd *InfoCmd) Item(section, key string) string {
if cmd.val == nil {
return ""
} else if cmd.val[section] == nil {
return ""
} else {
return cmd.val[section][key]
}
}
type MonitorStatus int
const (
monitorStatusIdle MonitorStatus = iota
monitorStatusStart
monitorStatusStop
)
type MonitorCmd struct {
baseCmd
ch chan string
status MonitorStatus
mu sync.Mutex
}
func newMonitorCmd(ctx context.Context, ch chan string) *MonitorCmd {
return &MonitorCmd{
baseCmd: baseCmd{
ctx: ctx,
args: []interface{}{"monitor"},
},
ch: ch,
status: monitorStatusIdle,
mu: sync.Mutex{},
}
}
func (cmd *MonitorCmd) String() string {
return cmdString(cmd, nil)
}
func (cmd *MonitorCmd) readReply(rd *proto.Reader) error {
ctx, cancel := context.WithCancel(cmd.ctx)
go func(ctx context.Context) {
for {
select {
case <-ctx.Done():
return
default:
err := cmd.readMonitor(rd, cancel)
if err != nil {
cmd.err = err
return
}
}
}
}(ctx)
return nil
}
func (cmd *MonitorCmd) readMonitor(rd *proto.Reader, cancel context.CancelFunc) error {
for {
cmd.mu.Lock()
st := cmd.status
cmd.mu.Unlock()
if pk, _ := rd.Peek(1); len(pk) != 0 && st == monitorStatusStart {
line, err := rd.ReadString()
if err != nil {
return err
}
cmd.ch <- line
}
if st == monitorStatusStop {
cancel()
break
}
}
return nil
}
func (cmd *MonitorCmd) Start() {
cmd.mu.Lock()
defer cmd.mu.Unlock()
cmd.status = monitorStatusStart
}
func (cmd *MonitorCmd) Stop() {
cmd.mu.Lock()
defer cmd.mu.Unlock()
cmd.status = monitorStatusStop
}

View File

@ -204,27 +204,28 @@ type Cmdable interface {
SlowLogGet(ctx context.Context, num int64) *SlowLogCmd
Time(ctx context.Context) *TimeCmd
DebugObject(ctx context.Context, key string) *StringCmd
MemoryUsage(ctx context.Context, key string, samples ...int) *IntCmd
ModuleLoadex(ctx context.Context, conf *ModuleLoadexConfig) *StringCmd
ACLCmdable
BitMapCmdable
ClusterCmdable
GearsCmdable
GenericCmdable
GeoCmdable
HashCmdable
HyperLogLogCmdable
GeoCmdable
GenericCmdable
ListCmdable
ProbabilisticCmdable
PubSubCmdable
ScriptingFunctionsCmdable
SetCmdable
SortedSetCmdable
ClusterCmdable
ScriptingFunctionsCmdable
StringCmdable
PubSubCmdable
GearsCmdable
ProbabilisticCmdable
TimeseriesCmdable
StreamCmdable
TimeseriesCmdable
JSONCmdable
}
type StatefulCmdable interface {
@ -569,6 +570,17 @@ func (c cmdable) Info(ctx context.Context, sections ...string) *StringCmd {
return cmd
}
func (c cmdable) InfoMap(ctx context.Context, sections ...string) *InfoCmd {
args := make([]interface{}, 1+len(sections))
args[0] = "info"
for i, section := range sections {
args[i+1] = section
}
cmd := NewInfoCmd(ctx, args...)
_ = c(ctx, cmd)
return cmd
}
func (c cmdable) LastSave(ctx context.Context) *IntCmd {
cmd := NewIntCmd(ctx, "lastsave")
_ = c(ctx, cmd)
@ -687,3 +699,20 @@ func (c cmdable) ModuleLoadex(ctx context.Context, conf *ModuleLoadexConfig) *St
_ = c(ctx, cmd)
return cmd
}
/*
Monitor - represents a Redis MONITOR command, allowing the user to capture
and process all commands sent to a Redis server. This mimics the behavior of
MONITOR in the redis-cli.
Notes:
- Using MONITOR blocks the connection to the server for itself. It needs a dedicated connection
- The user should create a channel of type string
- This runs concurrently in the background. Trigger via the Start and Stop functions
See further: Redis MONITOR command: https://redis.io/commands/monitor
*/
func (c cmdable) Monitor(ctx context.Context, ch chan string) *MonitorCmd {
cmd := newMonitorCmd(ctx, ch)
_ = c(ctx, cmd)
return cmd
}

View File

@ -107,7 +107,7 @@ var _ = Describe("Commands", func() {
Expect(time.Now()).To(BeTemporally("~", start.Add(waitAOF), 3*time.Second))
})
It("should Select", func() {
It("should Select", Label("NonRedisEnterprise"), func() {
pipe := client.Pipeline()
sel := pipe.Select(ctx, 1)
_, err := pipe.Exec(ctx)
@ -117,7 +117,7 @@ var _ = Describe("Commands", func() {
Expect(sel.Val()).To(Equal("OK"))
})
It("should SwapDB", func() {
It("should SwapDB", Label("NonRedisEnterprise"), func() {
pipe := client.Pipeline()
sel := pipe.SwapDB(ctx, 1, 2)
_, err := pipe.Exec(ctx)
@ -219,7 +219,7 @@ var _ = Describe("Commands", func() {
Expect(info).NotTo(BeNil())
})
It("should ClientPause", func() {
It("should ClientPause", Label("NonRedisEnterprise"), func() {
err := client.ClientPause(ctx, time.Second).Err()
Expect(err).NotTo(HaveOccurred())
@ -299,13 +299,13 @@ var _ = Describe("Commands", func() {
Expect(val).NotTo(BeEmpty())
})
It("should ConfigResetStat", func() {
It("should ConfigResetStat", Label("NonRedisEnterprise"), func() {
r := client.ConfigResetStat(ctx)
Expect(r.Err()).NotTo(HaveOccurred())
Expect(r.Val()).To(Equal("OK"))
})
It("should ConfigSet", func() {
It("should ConfigSet", Label("NonRedisEnterprise"), func() {
configGet := client.ConfigGet(ctx, "maxmemory")
Expect(configGet.Err()).NotTo(HaveOccurred())
Expect(configGet.Val()).To(HaveLen(1))
@ -317,7 +317,7 @@ var _ = Describe("Commands", func() {
Expect(configSet.Val()).To(Equal("OK"))
})
It("should ConfigRewrite", func() {
It("should ConfigRewrite", Label("NonRedisEnterprise"), func() {
configRewrite := client.ConfigRewrite(ctx)
Expect(configRewrite.Err()).NotTo(HaveOccurred())
Expect(configRewrite.Val()).To(Equal("OK"))
@ -335,6 +335,20 @@ var _ = Describe("Commands", func() {
Expect(info.Val()).NotTo(Equal(""))
})
It("should InfoMap", Label("redis.info"), func() {
info := client.InfoMap(ctx)
Expect(info.Err()).NotTo(HaveOccurred())
Expect(info.Val()).NotTo(BeNil())
info = client.InfoMap(ctx, "dummy")
Expect(info.Err()).NotTo(HaveOccurred())
Expect(info.Val()).To(BeNil())
info = client.InfoMap(ctx, "server")
Expect(info.Err()).NotTo(HaveOccurred())
Expect(info.Val()).To(HaveLen(1))
})
It("should Info cpu", func() {
info := client.Info(ctx, "cpu")
Expect(info.Err()).NotTo(HaveOccurred())
@ -350,20 +364,20 @@ var _ = Describe("Commands", func() {
Expect(info.Val()).To(ContainSubstring(`memory`))
})
It("should LastSave", func() {
It("should LastSave", Label("NonRedisEnterprise"), func() {
lastSave := client.LastSave(ctx)
Expect(lastSave.Err()).NotTo(HaveOccurred())
Expect(lastSave.Val()).NotTo(Equal(0))
})
It("should Save", func() {
It("should Save", Label("NonRedisEnterprise"), func() {
// workaround for "ERR Background save already in progress"
Eventually(func() string {
return client.Save(ctx).Val()
}, "10s").Should(Equal("OK"))
})
It("should SlaveOf", func() {
It("should SlaveOf", Label("NonRedisEnterprise"), func() {
slaveOf := client.SlaveOf(ctx, "localhost", "8888")
Expect(slaveOf.Err()).NotTo(HaveOccurred())
Expect(slaveOf.Val()).To(Equal("OK"))
@ -379,7 +393,7 @@ var _ = Describe("Commands", func() {
Expect(tm).To(BeTemporally("~", time.Now(), 3*time.Second))
})
It("should Command", func() {
It("should Command", Label("NonRedisEnterprise"), func() {
cmds, err := client.Command(ctx).Result()
Expect(err).NotTo(HaveOccurred())
Expect(len(cmds)).To(BeNumerically("~", 240, 25))
@ -610,7 +624,7 @@ var _ = Describe("Commands", func() {
Expect(keys.Val()).To(ConsistOf([]string{"four", "one", "three", "two"}))
})
It("should Migrate", func() {
It("should Migrate", Label("NonRedisEnterprise"), func() {
migrate := client.Migrate(ctx, "localhost", redisSecondaryPort, "key", 0, 0)
Expect(migrate.Err()).NotTo(HaveOccurred())
Expect(migrate.Val()).To(Equal("NOKEY"))
@ -624,7 +638,7 @@ var _ = Describe("Commands", func() {
Expect(migrate.Val()).To(Equal(""))
})
It("should Move", func() {
It("should Move", Label("NonRedisEnterprise"), func() {
move := client.Move(ctx, "key", 2)
Expect(move.Err()).NotTo(HaveOccurred())
Expect(move.Val()).To(Equal(false))
@ -785,7 +799,7 @@ var _ = Describe("Commands", func() {
Expect(randomKey.Val()).To(Equal("key"))
})
It("should Rename", func() {
It("should Rename", Label("NonRedisEnterprise"), func() {
set := client.Set(ctx, "key", "hello", 0)
Expect(set.Err()).NotTo(HaveOccurred())
Expect(set.Val()).To(Equal("OK"))
@ -799,7 +813,7 @@ var _ = Describe("Commands", func() {
Expect(get.Val()).To(Equal("hello"))
})
It("should RenameNX", func() {
It("should RenameNX", Label("NonRedisEnterprise"), func() {
set := client.Set(ctx, "key", "hello", 0)
Expect(set.Err()).NotTo(HaveOccurred())
Expect(set.Val()).To(Equal("OK"))
@ -900,7 +914,7 @@ var _ = Describe("Commands", func() {
Expect(els).To(Equal([]string{"1", "2"}))
})
It("should Sort and Get", func() {
It("should Sort and Get", Label("NonRedisEnterprise"), func() {
size, err := client.LPush(ctx, "list", "1").Result()
Expect(err).NotTo(HaveOccurred())
Expect(size).To(Equal(int64(1)))
@ -933,7 +947,7 @@ var _ = Describe("Commands", func() {
}
})
It("should Sort and Store", func() {
It("should Sort and Store", Label("NonRedisEnterprise"), func() {
size, err := client.LPush(ctx, "list", "1").Result()
Expect(err).NotTo(HaveOccurred())
Expect(size).To(Equal(int64(1)))
@ -1133,7 +1147,7 @@ var _ = Describe("Commands", func() {
Expect(bitCount.Val()).To(Equal(int64(6)))
})
It("should BitOpAnd", func() {
It("should BitOpAnd", Label("NonRedisEnterprise"), func() {
set := client.Set(ctx, "key1", "1", 0)
Expect(set.Err()).NotTo(HaveOccurred())
Expect(set.Val()).To(Equal("OK"))
@ -1151,7 +1165,7 @@ var _ = Describe("Commands", func() {
Expect(get.Val()).To(Equal("0"))
})
It("should BitOpOr", func() {
It("should BitOpOr", Label("NonRedisEnterprise"), func() {
set := client.Set(ctx, "key1", "1", 0)
Expect(set.Err()).NotTo(HaveOccurred())
Expect(set.Val()).To(Equal("OK"))
@ -1169,7 +1183,7 @@ var _ = Describe("Commands", func() {
Expect(get.Val()).To(Equal("1"))
})
It("should BitOpXor", func() {
It("should BitOpXor", Label("NonRedisEnterprise"), func() {
set := client.Set(ctx, "key1", "\xff", 0)
Expect(set.Err()).NotTo(HaveOccurred())
Expect(set.Val()).To(Equal("OK"))
@ -1187,7 +1201,7 @@ var _ = Describe("Commands", func() {
Expect(get.Val()).To(Equal("\xf0"))
})
It("should BitOpNot", func() {
It("should BitOpNot", Label("NonRedisEnterprise"), func() {
set := client.Set(ctx, "key1", "\x00", 0)
Expect(set.Err()).NotTo(HaveOccurred())
Expect(set.Val()).To(Equal("OK"))
@ -1265,6 +1279,20 @@ var _ = Describe("Commands", func() {
Expect(nn).To(Equal([]int64{0, 4}))
})
It("should BitFieldRO", func() {
nn, err := client.BitField(ctx, "mykey", "SET", "u8", 8, 255).Result()
Expect(err).NotTo(HaveOccurred())
Expect(nn).To(Equal([]int64{0}))
nn, err = client.BitFieldRO(ctx, "mykey", "u8", 0).Result()
Expect(err).NotTo(HaveOccurred())
Expect(nn).To(Equal([]int64{0}))
nn, err = client.BitFieldRO(ctx, "mykey", "u8", 0, "u4", 8, "u4", 12, "u4", 13).Result()
Expect(err).NotTo(HaveOccurred())
Expect(nn).To(Equal([]int64{0, 15, 15, 14}))
})
It("should Decr", func() {
set := client.Set(ctx, "key", "10", 0)
Expect(set.Err()).NotTo(HaveOccurred())
@ -1502,7 +1530,7 @@ var _ = Describe("Commands", func() {
}))
})
It("should MSetNX", func() {
It("should MSetNX", Label("NonRedisEnterprise"), func() {
mSetNX := client.MSetNX(ctx, "key1", "hello1", "key2", "hello2")
Expect(mSetNX.Err()).NotTo(HaveOccurred())
Expect(mSetNX.Val()).To(Equal(true))
@ -1967,7 +1995,7 @@ var _ = Describe("Commands", func() {
Expect(strLen.Val()).To(Equal(int64(0)))
})
It("should Copy", func() {
It("should Copy", Label("NonRedisEnterprise"), func() {
set := client.Set(ctx, "key", "hello", 0)
Expect(set.Err()).NotTo(HaveOccurred())
Expect(set.Val()).To(Equal("OK"))
@ -1999,7 +2027,7 @@ var _ = Describe("Commands", func() {
Expect(dryRun.Val()).To(Equal("OK"))
})
It("should fail module loadex", func() {
It("should fail module loadex", Label("NonRedisEnterprise"), func() {
dryRun := client.ModuleLoadex(ctx, &redis.ModuleLoadexConfig{
Path: "/path/to/non-existent-library.so",
Conf: map[string]interface{}{
@ -2047,7 +2075,7 @@ var _ = Describe("Commands", func() {
Expect(args).To(Equal(expectedArgs))
})
It("should ACL LOG", func() {
It("should ACL LOG", Label("NonRedisEnterprise"), func() {
err := client.Do(ctx, "acl", "setuser", "test", ">test", "on", "allkeys", "+get").Err()
Expect(err).NotTo(HaveOccurred())
@ -2080,7 +2108,7 @@ var _ = Describe("Commands", func() {
Expect(len(limitedLogEntries)).To(Equal(2))
})
It("should ACL LOG RESET", func() {
It("should ACL LOG RESET", Label("NonRedisEnterprise"), func() {
// Call ACL LOG RESET
resetCmd := client.ACLLogReset(ctx)
Expect(resetCmd.Err()).NotTo(HaveOccurred())
@ -2389,7 +2417,7 @@ var _ = Describe("Commands", func() {
})
Describe("hyperloglog", func() {
It("should PFMerge", func() {
It("should PFMerge", Label("NonRedisEnterprise"), func() {
pfAdd := client.PFAdd(ctx, "hll1", "1", "2", "3", "4", "5")
Expect(pfAdd.Err()).NotTo(HaveOccurred())
@ -2414,7 +2442,7 @@ var _ = Describe("Commands", func() {
})
Describe("lists", func() {
It("should BLPop", func() {
It("should BLPop", Label("NonRedisEnterprise"), func() {
rPush := client.RPush(ctx, "list1", "a", "b", "c")
Expect(rPush.Err()).NotTo(HaveOccurred())
@ -2468,7 +2496,7 @@ var _ = Describe("Commands", func() {
Expect(stats.Timeouts).To(Equal(uint32(0)))
})
It("should BRPop", func() {
It("should BRPop", Label("NonRedisEnterprise"), func() {
rPush := client.RPush(ctx, "list1", "a", "b", "c")
Expect(rPush.Err()).NotTo(HaveOccurred())
@ -2510,7 +2538,7 @@ var _ = Describe("Commands", func() {
}
})
It("should BRPopLPush", func() {
It("should BRPopLPush", Label("NonRedisEnterprise"), func() {
_, err := client.BRPopLPush(ctx, "list1", "list2", time.Second).Result()
Expect(err).To(Equal(redis.Nil))
@ -2522,7 +2550,7 @@ var _ = Describe("Commands", func() {
Expect(v).To(Equal("c"))
})
It("should LCS", func() {
It("should LCS", Label("NonRedisEnterprise"), func() {
err := client.MSet(ctx, "key1", "ohmytext", "key2", "mynewtext").Err()
Expect(err).NotTo(HaveOccurred())
@ -2636,7 +2664,7 @@ var _ = Describe("Commands", func() {
Expect(lRange.Val()).To(Equal([]string{"Hello", "There", "World"}))
})
It("should LMPop", func() {
It("should LMPop", Label("NonRedisEnterprise"), func() {
err := client.LPush(ctx, "list1", "one", "two", "three", "four", "five").Err()
Expect(err).NotTo(HaveOccurred())
@ -2676,7 +2704,7 @@ var _ = Describe("Commands", func() {
Expect(err).To(HaveOccurred())
})
It("should BLMPop", func() {
It("should BLMPop", Label("NonRedisEnterprise"), func() {
err := client.LPush(ctx, "list1", "one", "two", "three", "four", "five").Err()
Expect(err).NotTo(HaveOccurred())
@ -3010,7 +3038,7 @@ var _ = Describe("Commands", func() {
Expect(lRange.Val()).To(Equal([]string{"one", "two"}))
})
It("should RPopLPush", func() {
It("should RPopLPush", Label("NonRedisEnterprise"), func() {
rPush := client.RPush(ctx, "list", "one")
Expect(rPush.Err()).NotTo(HaveOccurred())
rPush = client.RPush(ctx, "list", "two")
@ -3079,7 +3107,7 @@ var _ = Describe("Commands", func() {
Expect(lRange.Val()).To(Equal([]string{}))
})
It("should LMove", func() {
It("should LMove", Label("NonRedisEnterprise"), func() {
rPush := client.RPush(ctx, "lmove1", "ichi")
Expect(rPush.Err()).NotTo(HaveOccurred())
Expect(rPush.Val()).To(Equal(int64(1)))
@ -3101,7 +3129,7 @@ var _ = Describe("Commands", func() {
Expect(lRange.Val()).To(Equal([]string{"san"}))
})
It("should BLMove", func() {
It("should BLMove", Label("NonRedisEnterprise"), func() {
rPush := client.RPush(ctx, "blmove1", "ichi")
Expect(rPush.Err()).NotTo(HaveOccurred())
Expect(rPush.Val()).To(Equal(int64(1)))
@ -3168,7 +3196,7 @@ var _ = Describe("Commands", func() {
Expect(sCard.Val()).To(Equal(int64(2)))
})
It("should SDiff", func() {
It("should SDiff", Label("NonRedisEnterprise"), func() {
sAdd := client.SAdd(ctx, "set1", "a")
Expect(sAdd.Err()).NotTo(HaveOccurred())
sAdd = client.SAdd(ctx, "set1", "b")
@ -3188,7 +3216,7 @@ var _ = Describe("Commands", func() {
Expect(sDiff.Val()).To(ConsistOf([]string{"a", "b"}))
})
It("should SDiffStore", func() {
It("should SDiffStore", Label("NonRedisEnterprise"), func() {
sAdd := client.SAdd(ctx, "set1", "a")
Expect(sAdd.Err()).NotTo(HaveOccurred())
sAdd = client.SAdd(ctx, "set1", "b")
@ -3212,7 +3240,7 @@ var _ = Describe("Commands", func() {
Expect(sMembers.Val()).To(ConsistOf([]string{"a", "b"}))
})
It("should SInter", func() {
It("should SInter", Label("NonRedisEnterprise"), func() {
sAdd := client.SAdd(ctx, "set1", "a")
Expect(sAdd.Err()).NotTo(HaveOccurred())
sAdd = client.SAdd(ctx, "set1", "b")
@ -3232,7 +3260,7 @@ var _ = Describe("Commands", func() {
Expect(sInter.Val()).To(Equal([]string{"c"}))
})
It("should SInterCard", func() {
It("should SInterCard", Label("NonRedisEnterprise"), func() {
sAdd := client.SAdd(ctx, "set1", "a")
Expect(sAdd.Err()).NotTo(HaveOccurred())
sAdd = client.SAdd(ctx, "set1", "b")
@ -3262,7 +3290,7 @@ var _ = Describe("Commands", func() {
Expect(sInterCard.Val()).To(Equal(int64(2)))
})
It("should SInterStore", func() {
It("should SInterStore", Label("NonRedisEnterprise"), func() {
sAdd := client.SAdd(ctx, "set1", "a")
Expect(sAdd.Err()).NotTo(HaveOccurred())
sAdd = client.SAdd(ctx, "set1", "b")
@ -3330,7 +3358,7 @@ var _ = Describe("Commands", func() {
Expect(sMembersMap.Val()).To(Equal(map[string]struct{}{"Hello": {}, "World": {}}))
})
It("should SMove", func() {
It("should SMove", Label("NonRedisEnterprise"), func() {
sAdd := client.SAdd(ctx, "set1", "one")
Expect(sAdd.Err()).NotTo(HaveOccurred())
sAdd = client.SAdd(ctx, "set1", "two")
@ -3438,7 +3466,7 @@ var _ = Describe("Commands", func() {
Expect(sMembers.Val()).To(ConsistOf([]string{"three", "two"}))
})
It("should SUnion", func() {
It("should SUnion", Label("NonRedisEnterprise"), func() {
sAdd := client.SAdd(ctx, "set1", "a")
Expect(sAdd.Err()).NotTo(HaveOccurred())
sAdd = client.SAdd(ctx, "set1", "b")
@ -3458,7 +3486,7 @@ var _ = Describe("Commands", func() {
Expect(sUnion.Val()).To(HaveLen(5))
})
It("should SUnionStore", func() {
It("should SUnionStore", Label("NonRedisEnterprise"), func() {
sAdd := client.SAdd(ctx, "set1", "a")
Expect(sAdd.Err()).NotTo(HaveOccurred())
sAdd = client.SAdd(ctx, "set1", "b")
@ -3484,7 +3512,7 @@ var _ = Describe("Commands", func() {
})
Describe("sorted sets", func() {
It("should BZPopMax", func() {
It("should BZPopMax", Label("NonRedisEnterprise"), func() {
err := client.ZAdd(ctx, "zset1", redis.Z{
Score: 1,
Member: "one",
@ -3566,7 +3594,7 @@ var _ = Describe("Commands", func() {
Expect(stats.Timeouts).To(Equal(uint32(0)))
})
It("should BZPopMin", func() {
It("should BZPopMin", Label("NonRedisEnterprise"), func() {
err := client.ZAdd(ctx, "zset1", redis.Z{
Score: 1,
Member: "one",
@ -3694,28 +3722,28 @@ var _ = Describe("Commands", func() {
It("should ZAdd bytes", func() {
added, err := client.ZAdd(ctx, "zset", redis.Z{
Score: 1,
Member: []byte("one"),
Member: "one",
}).Result()
Expect(err).NotTo(HaveOccurred())
Expect(added).To(Equal(int64(1)))
added, err = client.ZAdd(ctx, "zset", redis.Z{
Score: 1,
Member: []byte("uno"),
Member: "uno",
}).Result()
Expect(err).NotTo(HaveOccurred())
Expect(added).To(Equal(int64(1)))
added, err = client.ZAdd(ctx, "zset", redis.Z{
Score: 2,
Member: []byte("two"),
Member: "two",
}).Result()
Expect(err).NotTo(HaveOccurred())
Expect(added).To(Equal(int64(1)))
added, err = client.ZAdd(ctx, "zset", redis.Z{
Score: 3,
Member: []byte("two"),
Member: "two",
}).Result()
Expect(err).NotTo(HaveOccurred())
Expect(added).To(Equal(int64(0)))
@ -4148,7 +4176,7 @@ var _ = Describe("Commands", func() {
}}))
})
It("should ZInterStore", func() {
It("should ZInterStore", Label("NonRedisEnterprise"), func() {
err := client.ZAdd(ctx, "zset1", redis.Z{
Score: 1,
Member: "one",
@ -4185,7 +4213,7 @@ var _ = Describe("Commands", func() {
}}))
})
It("should ZMPop", func() {
It("should ZMPop", Label("NonRedisEnterprise"), func() {
err := client.ZAdd(ctx, "zset", redis.Z{Score: 1, Member: "one"}).Err()
Expect(err).NotTo(HaveOccurred())
err = client.ZAdd(ctx, "zset", redis.Z{Score: 2, Member: "two"}).Err()
@ -4259,7 +4287,7 @@ var _ = Describe("Commands", func() {
}}))
})
It("should BZMPop", func() {
It("should BZMPop", Label("NonRedisEnterprise"), func() {
err := client.ZAdd(ctx, "zset", redis.Z{Score: 1, Member: "one"}).Err()
Expect(err).NotTo(HaveOccurred())
err = client.ZAdd(ctx, "zset", redis.Z{Score: 2, Member: "two"}).Err()
@ -4799,7 +4827,7 @@ var _ = Describe("Commands", func() {
Expect(vals).To(Equal([]redis.Z{}))
})
It("should ZRangeStore", func() {
It("should ZRangeStore", Label("NonRedisEnterprise"), func() {
added, err := client.ZAddArgs(ctx, "zset", redis.ZAddArgs{
Members: []redis.Z{
{Score: 1, Member: "one"},
@ -5175,7 +5203,7 @@ var _ = Describe("Commands", func() {
Expect(zScore.Val()).To(Equal(1.001))
})
It("should ZUnion", func() {
It("should ZUnion", Label("NonRedisEnterprise"), func() {
err := client.ZAddArgs(ctx, "zset1", redis.ZAddArgs{
Members: []redis.Z{
{Score: 1, Member: "one"},
@ -5214,7 +5242,7 @@ var _ = Describe("Commands", func() {
}))
})
It("should ZUnionStore", func() {
It("should ZUnionStore", Label("NonRedisEnterprise"), func() {
err := client.ZAdd(ctx, "zset1", redis.Z{Score: 1, Member: "one"}).Err()
Expect(err).NotTo(HaveOccurred())
err = client.ZAdd(ctx, "zset1", redis.Z{Score: 2, Member: "two"}).Err()
@ -5270,7 +5298,7 @@ var _ = Describe("Commands", func() {
))
})
It("should ZDiff", func() {
It("should ZDiff", Label("NonRedisEnterprise"), func() {
err := client.ZAdd(ctx, "zset1", redis.Z{Score: 1, Member: "one"}).Err()
Expect(err).NotTo(HaveOccurred())
err = client.ZAdd(ctx, "zset1", redis.Z{Score: 2, Member: "two"}).Err()
@ -5285,7 +5313,7 @@ var _ = Describe("Commands", func() {
Expect(v).To(Equal([]string{"two", "three"}))
})
It("should ZDiffWithScores", func() {
It("should ZDiffWithScores", Label("NonRedisEnterprise"), func() {
err := client.ZAdd(ctx, "zset1", redis.Z{Score: 1, Member: "one"}).Err()
Expect(err).NotTo(HaveOccurred())
err = client.ZAdd(ctx, "zset1", redis.Z{Score: 2, Member: "two"}).Err()
@ -5309,7 +5337,7 @@ var _ = Describe("Commands", func() {
}))
})
It("should ZInter", func() {
It("should ZInter", Label("NonRedisEnterprise"), func() {
err := client.ZAdd(ctx, "zset1", redis.Z{Score: 1, Member: "one"}).Err()
Expect(err).NotTo(HaveOccurred())
err = client.ZAdd(ctx, "zset1", redis.Z{Score: 2, Member: "two"}).Err()
@ -5328,7 +5356,7 @@ var _ = Describe("Commands", func() {
Expect(v).To(Equal([]string{"one", "two"}))
})
It("should ZInterCard", func() {
It("should ZInterCard", Label("NonRedisEnterprise"), func() {
err := client.ZAdd(ctx, "zset1", redis.Z{Score: 1, Member: "one"}).Err()
Expect(err).NotTo(HaveOccurred())
err = client.ZAdd(ctx, "zset1", redis.Z{Score: 2, Member: "two"}).Err()
@ -5354,7 +5382,7 @@ var _ = Describe("Commands", func() {
Expect(sInterCard.Val()).To(Equal(int64(2)))
})
It("should ZInterWithScores", func() {
It("should ZInterWithScores", Label("NonRedisEnterprise"), func() {
err := client.ZAdd(ctx, "zset1", redis.Z{Score: 1, Member: "one"}).Err()
Expect(err).NotTo(HaveOccurred())
err = client.ZAdd(ctx, "zset1", redis.Z{Score: 2, Member: "two"}).Err()
@ -5384,7 +5412,7 @@ var _ = Describe("Commands", func() {
}))
})
It("should ZDiffStore", func() {
It("should ZDiffStore", Label("NonRedisEnterprise"), func() {
err := client.ZAdd(ctx, "zset1", redis.Z{Score: 1, Member: "one"}).Err()
Expect(err).NotTo(HaveOccurred())
err = client.ZAdd(ctx, "zset1", redis.Z{Score: 2, Member: "two"}).Err()
@ -6115,7 +6143,7 @@ var _ = Describe("Commands", func() {
Expect(res[1].Name).To(Equal("Catania"))
})
It("should geo radius and store the result", func() {
It("should geo radius and store the result", Label("NonRedisEnterprise"), func() {
n, err := client.GeoRadiusStore(ctx, "Sicily", 15, 37, &redis.GeoRadiusQuery{
Radius: 200,
Store: "result",
@ -6135,7 +6163,7 @@ var _ = Describe("Commands", func() {
}))
})
It("should geo radius and store dist", func() {
It("should geo radius and store dist", Label("NonRedisEnterprise"), func() {
n, err := client.GeoRadiusStore(ctx, "Sicily", 15, 37, &redis.GeoRadiusQuery{
Radius: 200,
StoreDist: "result",
@ -6417,7 +6445,7 @@ var _ = Describe("Commands", func() {
}))
})
It("should geo search store", func() {
It("should geo search store", Label("NonRedisEnterprise"), func() {
q := &redis.GeoSearchStoreQuery{
GeoSearchQuery: redis.GeoSearchQuery{
Longitude: 15,
@ -6677,7 +6705,7 @@ var _ = Describe("Commands", func() {
q = redis.FunctionListQuery{}
})
It("Loads a new library", func() {
It("Loads a new library", Label("NonRedisEnterprise"), func() {
functionLoad := client.FunctionLoad(ctx, lib1Code)
Expect(functionLoad.Err()).NotTo(HaveOccurred())
Expect(functionLoad.Val()).To(Equal(lib1.Name))
@ -6687,7 +6715,7 @@ var _ = Describe("Commands", func() {
Expect(functionList.Val()).To(HaveLen(1))
})
It("Loads and replaces a new library", func() {
It("Loads and replaces a new library", Label("NonRedisEnterprise"), func() {
// Load a library for the first time
err := client.FunctionLoad(ctx, lib1Code).Err()
Expect(err).NotTo(HaveOccurred())
@ -6758,7 +6786,7 @@ var _ = Describe("Commands", func() {
// Add test for a long-running function, once we make the test for `function stats` pass
})
It("Lists registered functions", func() {
It("Lists registered functions", Label("NonRedisEnterprise"), func() {
err := client.FunctionLoad(ctx, lib1Code).Err()
Expect(err).NotTo(HaveOccurred())
@ -6797,7 +6825,7 @@ var _ = Describe("Commands", func() {
Expect(err).To(Equal(redis.Nil))
})
It("Dump and restores all libraries", func() {
It("Dump and restores all libraries", Label("NonRedisEnterprise"), func() {
err := client.FunctionLoad(ctx, lib1Code).Err()
Expect(err).NotTo(HaveOccurred())
err = client.FunctionLoad(ctx, lib2Code).Err()

View File

@ -2,6 +2,7 @@ package redis
import (
"context"
"errors"
"io"
"net"
"strings"
@ -15,11 +16,11 @@ var ErrClosed = pool.ErrClosed
// HasErrorPrefix checks if the err is a Redis error and the message contains a prefix.
func HasErrorPrefix(err error, prefix string) bool {
err, ok := err.(Error)
if !ok {
var rErr Error
if !errors.As(err, &rErr) {
return false
}
msg := err.Error()
msg := rErr.Error()
msg = strings.TrimPrefix(msg, "ERR ") // KVRocks adds such prefix
return strings.HasPrefix(msg, prefix)
}

View File

@ -5,7 +5,7 @@ go 1.18
replace github.com/redis/go-redis/v9 => ../..
require (
github.com/redis/go-redis/v9 v9.2.1
github.com/redis/go-redis/v9 v9.3.1
go.uber.org/zap v1.24.0
)

View File

@ -4,7 +4,7 @@ go 1.18
replace github.com/redis/go-redis/v9 => ../..
require github.com/redis/go-redis/v9 v9.2.1
require github.com/redis/go-redis/v9 v9.3.1
require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect

View File

@ -1,10 +1,10 @@
module github.com/redis/go-redis/example/redis-bloom
module github.com/redis/go-redis/example/lua-scripting
go 1.18
replace github.com/redis/go-redis/v9 => ../..
require github.com/redis/go-redis/v9 v9.2.1
require github.com/redis/go-redis/v9 v9.3.1
require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect

View File

@ -9,8 +9,8 @@ replace github.com/redis/go-redis/extra/redisotel/v9 => ../../extra/redisotel
replace github.com/redis/go-redis/extra/rediscmd/v9 => ../../extra/rediscmd
require (
github.com/redis/go-redis/extra/redisotel/v9 v9.2.1
github.com/redis/go-redis/v9 v9.2.1
github.com/redis/go-redis/extra/redisotel/v9 v9.3.1
github.com/redis/go-redis/v9 v9.3.1
github.com/uptrace/uptrace-go v1.16.0
go.opentelemetry.io/otel v1.16.0
)
@ -23,7 +23,7 @@ require (
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.2 // indirect
github.com/redis/go-redis/extra/rediscmd/v9 v9.2.1 // indirect
github.com/redis/go-redis/extra/rediscmd/v9 v9.3.1 // indirect
go.opentelemetry.io/contrib/instrumentation/runtime v0.42.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.16.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.39.0 // indirect
@ -36,10 +36,10 @@ require (
go.opentelemetry.io/otel/sdk/metric v0.39.0 // indirect
go.opentelemetry.io/otel/trace v1.16.0 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/grpc v1.55.0 // indirect
google.golang.org/grpc v1.56.3 // indirect
google.golang.org/protobuf v1.30.0 // indirect
)

View File

@ -35,10 +35,12 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/bsm/ginkgo/v2 v2.7.0 h1:ItPMPH90RbmZJt5GtkcNvIRuGEdwlBItdNVoyzaNQao=
github.com/bsm/ginkgo/v2 v2.7.0/go.mod h1:AiKlXPm7ItEHNc/2+OkrNG4E0ITzojb9/xWzvQ9XZ9w=
github.com/bsm/gomega v1.26.0 h1:LhQm+AFcgV2M0WyKroMASzAzCAJVpAxQXv4SaI9a69Y=
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
github.com/bsm/gomega v1.26.0/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM=
github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
@ -257,8 +259,8 @@ golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81R
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@ -301,8 +303,8 @@ golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@ -310,8 +312,8 @@ golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
@ -430,8 +432,8 @@ google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTp
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34=
google.golang.org/grpc v1.42.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU=
google.golang.org/grpc v1.55.0 h1:3Oj82/tFSCeUrRTg/5E/7d/W5A1tj6Ky1ABAuZuv5ag=
google.golang.org/grpc v1.55.0/go.mod h1:iYEXKGkEBhg1PjZQvoYEVPTDkHo1/bjTnfwTeGONTY8=
google.golang.org/grpc v1.56.3 h1:8I4C0Yq1EjstUzUJzpcRVbuYA2mODtEmpWiQoN/b2nc=
google.golang.org/grpc v1.56.3/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=

View File

@ -4,7 +4,7 @@ go 1.18
replace github.com/redis/go-redis/v9 => ../..
require github.com/redis/go-redis/v9 v9.2.1
require github.com/redis/go-redis/v9 v9.3.1
require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect

View File

@ -6,7 +6,7 @@ replace github.com/redis/go-redis/v9 => ../..
require (
github.com/davecgh/go-spew v1.1.1
github.com/redis/go-redis/v9 v9.2.1
github.com/redis/go-redis/v9 v9.3.1
)
require (

View File

@ -657,6 +657,11 @@ func ExampleNewUniversalClient_cluster() {
}
func ExampleClient_SlowLogGet() {
if RECluster {
// skip slowlog test for cluster
fmt.Println(2)
return
}
const key = "slowlog-log-slower-than"
old := rdb.ConfigGet(ctx, key).Val()

View File

@ -8,7 +8,7 @@ replace github.com/redis/go-redis/extra/rediscmd/v9 => ../rediscmd
require (
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/redis/go-redis/extra/rediscmd/v9 v9.2.1
github.com/redis/go-redis/v9 v9.2.1
github.com/redis/go-redis/extra/rediscmd/v9 v9.3.1
github.com/redis/go-redis/v9 v9.3.1
go.opencensus.io v0.24.0
)

View File

@ -7,5 +7,5 @@ replace github.com/redis/go-redis/v9 => ../..
require (
github.com/bsm/ginkgo/v2 v2.7.0
github.com/bsm/gomega v1.26.0
github.com/redis/go-redis/v9 v9.2.1
github.com/redis/go-redis/v9 v9.3.1
)

View File

@ -7,8 +7,8 @@ replace github.com/redis/go-redis/v9 => ../..
replace github.com/redis/go-redis/extra/rediscmd/v9 => ../rediscmd
require (
github.com/redis/go-redis/extra/rediscmd/v9 v9.2.1
github.com/redis/go-redis/v9 v9.2.1
github.com/redis/go-redis/extra/rediscmd/v9 v9.3.1
github.com/redis/go-redis/v9 v9.3.1
go.opentelemetry.io/otel v1.16.0
go.opentelemetry.io/otel/metric v1.16.0
go.opentelemetry.io/otel/sdk v1.16.0

View File

@ -6,7 +6,7 @@ replace github.com/redis/go-redis/v9 => ../..
require (
github.com/prometheus/client_golang v1.14.0
github.com/redis/go-redis/v9 v9.2.1
github.com/redis/go-redis/v9 v9.3.1
)
require (

View File

@ -8,6 +8,8 @@ import (
. "github.com/bsm/ginkgo/v2"
. "github.com/bsm/gomega"
"github.com/redis/go-redis/v9/internal/util"
)
type data struct {
@ -29,6 +31,7 @@ type data struct {
Float float32 `redis:"float"`
Float64 float64 `redis:"float64"`
Bool bool `redis:"bool"`
BoolRef *bool `redis:"boolRef"`
}
type TimeRFC3339Nano struct {
@ -117,10 +120,10 @@ var _ = Describe("Scan", func() {
Expect(Scan(&d, i{"key"}, i{"value"})).NotTo(HaveOccurred())
Expect(d).To(Equal(data{}))
keys := i{"string", "byte", "int", "int64", "uint", "uint64", "float", "float64", "bool"}
keys := i{"string", "byte", "int", "int64", "uint", "uint64", "float", "float64", "bool", "boolRef"}
vals := i{
"str!", "bytes!", "123", "123456789123456789", "456", "987654321987654321",
"123.456", "123456789123456789.987654321987654321", "1",
"123.456", "123456789123456789.987654321987654321", "1", "1",
}
Expect(Scan(&d, keys, vals)).NotTo(HaveOccurred())
Expect(d).To(Equal(data{
@ -133,6 +136,7 @@ var _ = Describe("Scan", func() {
Float: 123.456,
Float64: 1.2345678912345678e+17,
Bool: true,
BoolRef: util.ToPtr(true),
}))
// Scan a different type with the same values to test that
@ -167,6 +171,7 @@ var _ = Describe("Scan", func() {
Float: 1.0,
Float64: 1.2345678912345678e+17,
Bool: true,
BoolRef: util.ToPtr(true),
}))
})

View File

@ -61,7 +61,11 @@ func newStructSpec(t reflect.Type, fieldTag string) *structSpec {
}
// Use the built-in decoder.
out.set(tag, &structField{index: i, fn: decoders[f.Type.Kind()]})
kind := f.Type.Kind()
if kind == reflect.Pointer {
kind = f.Type.Elem().Kind()
}
out.set(tag, &structField{index: i, fn: decoders[kind]})
}
return out

View File

@ -263,6 +263,7 @@ func (p *ConnPool) Get(ctx context.Context) (*Conn, error) {
p.connsMu.Unlock()
if err != nil {
p.freeTurn()
return nil, err
}

View File

@ -65,37 +65,68 @@ func (w *Writer) WriteArg(v interface{}) error {
return w.string("")
case string:
return w.string(v)
case *string:
return w.string(*v)
case []byte:
return w.bytes(v)
case int:
return w.int(int64(v))
case *int:
return w.int(int64(*v))
case int8:
return w.int(int64(v))
case *int8:
return w.int(int64(*v))
case int16:
return w.int(int64(v))
case *int16:
return w.int(int64(*v))
case int32:
return w.int(int64(v))
case *int32:
return w.int(int64(*v))
case int64:
return w.int(v)
case *int64:
return w.int(*v)
case uint:
return w.uint(uint64(v))
case *uint:
return w.uint(uint64(*v))
case uint8:
return w.uint(uint64(v))
case *uint8:
return w.uint(uint64(*v))
case uint16:
return w.uint(uint64(v))
case *uint16:
return w.uint(uint64(*v))
case uint32:
return w.uint(uint64(v))
case *uint32:
return w.uint(uint64(*v))
case uint64:
return w.uint(v)
case *uint64:
return w.uint(*v)
case float32:
return w.float(float64(v))
case *float32:
return w.float(float64(*v))
case float64:
return w.float(v)
case *float64:
return w.float(*v)
case bool:
if v {
return w.int(1)
}
return w.int(0)
case *bool:
if *v {
return w.int(1)
}
return w.int(0)
case time.Time:
w.numBuf = v.AppendFormat(w.numBuf[:0], time.RFC3339Nano)
return w.bytes(w.numBuf)

View File

@ -12,6 +12,7 @@ import (
. "github.com/bsm/gomega"
"github.com/redis/go-redis/v9/internal/proto"
"github.com/redis/go-redis/v9/internal/util"
)
type MyType struct{}
@ -100,3 +101,54 @@ func BenchmarkWriteBuffer_Append(b *testing.B) {
}
}
}
var _ = Describe("WriteArg", func() {
var buf *bytes.Buffer
var wr *proto.Writer
BeforeEach(func() {
buf = new(bytes.Buffer)
wr = proto.NewWriter(buf)
})
args := map[any]string{
"hello": "$5\r\nhello\r\n",
int(10): "$2\r\n10\r\n",
util.ToPtr(int(10)): "$2\r\n10\r\n",
int8(10): "$2\r\n10\r\n",
util.ToPtr(int8(10)): "$2\r\n10\r\n",
int16(10): "$2\r\n10\r\n",
util.ToPtr(int16(10)): "$2\r\n10\r\n",
int32(10): "$2\r\n10\r\n",
util.ToPtr(int32(10)): "$2\r\n10\r\n",
int64(10): "$2\r\n10\r\n",
util.ToPtr(int64(10)): "$2\r\n10\r\n",
uint(10): "$2\r\n10\r\n",
util.ToPtr(uint(10)): "$2\r\n10\r\n",
uint8(10): "$2\r\n10\r\n",
util.ToPtr(uint8(10)): "$2\r\n10\r\n",
uint16(10): "$2\r\n10\r\n",
util.ToPtr(uint16(10)): "$2\r\n10\r\n",
uint32(10): "$2\r\n10\r\n",
util.ToPtr(uint32(10)): "$2\r\n10\r\n",
uint64(10): "$2\r\n10\r\n",
util.ToPtr(uint64(10)): "$2\r\n10\r\n",
float32(10.3): "$18\r\n10.300000190734863\r\n",
util.ToPtr(float32(10.3)): "$18\r\n10.300000190734863\r\n",
float64(10.3): "$4\r\n10.3\r\n",
util.ToPtr(float64(10.3)): "$4\r\n10.3\r\n",
bool(true): "$1\r\n1\r\n",
bool(false): "$1\r\n0\r\n",
util.ToPtr(bool(true)): "$1\r\n1\r\n",
util.ToPtr(bool(false)): "$1\r\n0\r\n",
}
for arg, expect := range args {
arg, expect := arg, expect
It(fmt.Sprintf("should write arg of type %T", arg), func() {
err := wr.WriteArg(arg)
Expect(err).NotTo(HaveOccurred())
Expect(buf.String()).To(Equal(expect))
})
}
})

5
internal/util/type.go Normal file
View File

@ -0,0 +1,5 @@
package util
func ToPtr[T any](v T) *T {
return &v
}

599
json.go Normal file
View File

@ -0,0 +1,599 @@
package redis
import (
"context"
"encoding/json"
"strings"
"github.com/redis/go-redis/v9/internal/proto"
"github.com/redis/go-redis/v9/internal/util"
)
// -------------------------------------------
type JSONCmdable interface {
JSONArrAppend(ctx context.Context, key, path string, values ...interface{}) *IntSliceCmd
JSONArrIndex(ctx context.Context, key, path string, value ...interface{}) *IntSliceCmd
JSONArrIndexWithArgs(ctx context.Context, key, path string, options *JSONArrIndexArgs, value ...interface{}) *IntSliceCmd
JSONArrInsert(ctx context.Context, key, path string, index int64, values ...interface{}) *IntSliceCmd
JSONArrLen(ctx context.Context, key, path string) *IntSliceCmd
JSONArrPop(ctx context.Context, key, path string, index int) *StringSliceCmd
JSONArrTrim(ctx context.Context, key, path string) *IntSliceCmd
JSONArrTrimWithArgs(ctx context.Context, key, path string, options *JSONArrTrimArgs) *IntSliceCmd
JSONClear(ctx context.Context, key, path string) *IntCmd
JSONDebugMemory(ctx context.Context, key, path string) *IntCmd
JSONDel(ctx context.Context, key, path string) *IntCmd
JSONForget(ctx context.Context, key, path string) *IntCmd
JSONGet(ctx context.Context, key string, paths ...string) *JSONCmd
JSONGetWithArgs(ctx context.Context, key string, options *JSONGetArgs, paths ...string) *JSONCmd
JSONMerge(ctx context.Context, key, path string, value string) *StatusCmd
JSONMSetArgs(ctx context.Context, docs []JSONSetArgs) *StatusCmd
JSONMSet(ctx context.Context, params ...interface{}) *StatusCmd
JSONMGet(ctx context.Context, path string, keys ...string) *JSONSliceCmd
JSONNumIncrBy(ctx context.Context, key, path string, value float64) *JSONCmd
JSONObjKeys(ctx context.Context, key, path string) *SliceCmd
JSONObjLen(ctx context.Context, key, path string) *IntPointerSliceCmd
JSONSet(ctx context.Context, key, path string, value interface{}) *StatusCmd
JSONSetMode(ctx context.Context, key, path string, value interface{}, mode string) *StatusCmd
JSONStrAppend(ctx context.Context, key, path, value string) *IntPointerSliceCmd
JSONStrLen(ctx context.Context, key, path string) *IntPointerSliceCmd
JSONToggle(ctx context.Context, key, path string) *IntPointerSliceCmd
JSONType(ctx context.Context, key, path string) *JSONSliceCmd
}
type JSONSetArgs struct {
Key string
Path string
Value interface{}
}
type JSONArrIndexArgs struct {
Start int
Stop *int
}
type JSONArrTrimArgs struct {
Start int
Stop *int
}
type JSONCmd struct {
baseCmd
val string
expanded []interface{}
}
var _ Cmder = (*JSONCmd)(nil)
func newJSONCmd(ctx context.Context, args ...interface{}) *JSONCmd {
return &JSONCmd{
baseCmd: baseCmd{
ctx: ctx,
args: args,
},
}
}
func (cmd *JSONCmd) String() string {
return cmdString(cmd, cmd.val)
}
func (cmd *JSONCmd) SetVal(val string) {
cmd.val = val
}
func (cmd *JSONCmd) Val() string {
if len(cmd.val) == 0 && cmd.expanded != nil {
val, err := json.Marshal(cmd.expanded)
if err != nil {
cmd.SetErr(err)
return ""
}
return string(val)
} else {
return cmd.val
}
}
func (cmd *JSONCmd) Result() (string, error) {
return cmd.Val(), cmd.Err()
}
func (cmd JSONCmd) Expanded() (interface{}, error) {
if len(cmd.val) != 0 && cmd.expanded == nil {
err := json.Unmarshal([]byte(cmd.val), &cmd.expanded)
if err != nil {
return "", err
}
}
return cmd.expanded, nil
}
func (cmd *JSONCmd) readReply(rd *proto.Reader) error {
// nil response from JSON.(M)GET (cmd.baseCmd.err will be "redis: nil")
if cmd.baseCmd.Err() == Nil {
cmd.val = ""
return Nil
}
if readType, err := rd.PeekReplyType(); err != nil {
return err
} else if readType == proto.RespArray {
size, err := rd.ReadArrayLen()
if err != nil {
return err
}
expanded := make([]interface{}, size)
for i := 0; i < size; i++ {
if expanded[i], err = rd.ReadReply(); err != nil {
return err
}
}
cmd.expanded = expanded
} else {
if str, err := rd.ReadString(); err != nil && err != Nil {
return err
} else if str == "" || err == Nil {
cmd.val = ""
} else {
cmd.val = str
}
}
return nil
}
// -------------------------------------------
type JSONSliceCmd struct {
baseCmd
val []interface{}
}
func NewJSONSliceCmd(ctx context.Context, args ...interface{}) *JSONSliceCmd {
return &JSONSliceCmd{
baseCmd: baseCmd{
ctx: ctx,
args: args,
},
}
}
func (cmd *JSONSliceCmd) String() string {
return cmdString(cmd, cmd.val)
}
func (cmd *JSONSliceCmd) SetVal(val []interface{}) {
cmd.val = val
}
func (cmd *JSONSliceCmd) Val() []interface{} {
return cmd.val
}
func (cmd *JSONSliceCmd) Result() ([]interface{}, error) {
return cmd.Val(), cmd.Err()
}
func (cmd *JSONSliceCmd) readReply(rd *proto.Reader) error {
if cmd.baseCmd.Err() == Nil {
cmd.val = nil
return Nil
}
if readType, err := rd.PeekReplyType(); err != nil {
return err
} else if readType == proto.RespArray {
response, err := rd.ReadReply()
if err != nil {
return nil
} else {
cmd.val = response.([]interface{})
}
} else {
n, err := rd.ReadArrayLen()
if err != nil {
return err
}
cmd.val = make([]interface{}, n)
for i := 0; i < len(cmd.val); i++ {
switch s, err := rd.ReadString(); {
case err == Nil:
cmd.val[i] = ""
case err != nil:
return err
default:
cmd.val[i] = s
}
}
}
return nil
}
/*******************************************************************************
*
* IntPointerSliceCmd
* used to represent a RedisJSON response where the result is either an integer or nil
*
*******************************************************************************/
type IntPointerSliceCmd struct {
baseCmd
val []*int64
}
// NewIntPointerSliceCmd initialises an IntPointerSliceCmd
func NewIntPointerSliceCmd(ctx context.Context, args ...interface{}) *IntPointerSliceCmd {
return &IntPointerSliceCmd{
baseCmd: baseCmd{
ctx: ctx,
args: args,
},
}
}
func (cmd *IntPointerSliceCmd) String() string {
return cmdString(cmd, cmd.val)
}
func (cmd *IntPointerSliceCmd) SetVal(val []*int64) {
cmd.val = val
}
func (cmd *IntPointerSliceCmd) Val() []*int64 {
return cmd.val
}
func (cmd *IntPointerSliceCmd) Result() ([]*int64, error) {
return cmd.Val(), cmd.Err()
}
func (cmd *IntPointerSliceCmd) readReply(rd *proto.Reader) error {
n, err := rd.ReadArrayLen()
if err != nil {
return err
}
cmd.val = make([]*int64, n)
for i := 0; i < len(cmd.val); i++ {
val, err := rd.ReadInt()
if err != nil && err != Nil {
return err
} else if err != Nil {
cmd.val[i] = &val
}
}
return nil
}
//------------------------------------------------------------------------------
// JSONArrAppend adds the provided JSON values to the end of the array at the given path.
// For more information, see https://redis.io/commands/json.arrappend
func (c cmdable) JSONArrAppend(ctx context.Context, key, path string, values ...interface{}) *IntSliceCmd {
args := []interface{}{"JSON.ARRAPPEND", key, path}
args = append(args, values...)
cmd := NewIntSliceCmd(ctx, args...)
_ = c(ctx, cmd)
return cmd
}
// JSONArrIndex searches for the first occurrence of the provided JSON value in the array at the given path.
// For more information, see https://redis.io/commands/json.arrindex
func (c cmdable) JSONArrIndex(ctx context.Context, key, path string, value ...interface{}) *IntSliceCmd {
args := []interface{}{"JSON.ARRINDEX", key, path}
args = append(args, value...)
cmd := NewIntSliceCmd(ctx, args...)
_ = c(ctx, cmd)
return cmd
}
// JSONArrIndexWithArgs searches for the first occurrence of a JSON value in an array while allowing the start and
// stop options to be provided.
// For more information, see https://redis.io/commands/json.arrindex
func (c cmdable) JSONArrIndexWithArgs(ctx context.Context, key, path string, options *JSONArrIndexArgs, value ...interface{}) *IntSliceCmd {
args := []interface{}{"JSON.ARRINDEX", key, path}
args = append(args, value...)
if options != nil {
args = append(args, options.Start)
if options.Stop != nil {
args = append(args, *options.Stop)
}
}
cmd := NewIntSliceCmd(ctx, args...)
_ = c(ctx, cmd)
return cmd
}
// JSONArrInsert inserts the JSON values into the array at the specified path before the index (shifts to the right).
// For more information, see https://redis.io/commands/json.arrinsert
func (c cmdable) JSONArrInsert(ctx context.Context, key, path string, index int64, values ...interface{}) *IntSliceCmd {
args := []interface{}{"JSON.ARRINSERT", key, path, index}
args = append(args, values...)
cmd := NewIntSliceCmd(ctx, args...)
_ = c(ctx, cmd)
return cmd
}
// JSONArrLen reports the length of the JSON array at the specified path in the given key.
// For more information, see https://redis.io/commands/json.arrlen
func (c cmdable) JSONArrLen(ctx context.Context, key, path string) *IntSliceCmd {
args := []interface{}{"JSON.ARRLEN", key, path}
cmd := NewIntSliceCmd(ctx, args...)
_ = c(ctx, cmd)
return cmd
}
// JSONArrPop removes and returns an element from the specified index in the array.
// For more information, see https://redis.io/commands/json.arrpop
func (c cmdable) JSONArrPop(ctx context.Context, key, path string, index int) *StringSliceCmd {
args := []interface{}{"JSON.ARRPOP", key, path, index}
cmd := NewStringSliceCmd(ctx, args...)
_ = c(ctx, cmd)
return cmd
}
// JSONArrTrim trims an array to contain only the specified inclusive range of elements.
// For more information, see https://redis.io/commands/json.arrtrim
func (c cmdable) JSONArrTrim(ctx context.Context, key, path string) *IntSliceCmd {
args := []interface{}{"JSON.ARRTRIM", key, path}
cmd := NewIntSliceCmd(ctx, args...)
_ = c(ctx, cmd)
return cmd
}
// JSONArrTrimWithArgs trims an array to contain only the specified inclusive range of elements.
// For more information, see https://redis.io/commands/json.arrtrim
func (c cmdable) JSONArrTrimWithArgs(ctx context.Context, key, path string, options *JSONArrTrimArgs) *IntSliceCmd {
args := []interface{}{"JSON.ARRTRIM", key, path}
if options != nil {
args = append(args, options.Start)
if options.Stop != nil {
args = append(args, *options.Stop)
}
}
cmd := NewIntSliceCmd(ctx, args...)
_ = c(ctx, cmd)
return cmd
}
// JSONClear clears container values (arrays/objects) and sets numeric values to 0.
// For more information, see https://redis.io/commands/json.clear
func (c cmdable) JSONClear(ctx context.Context, key, path string) *IntCmd {
args := []interface{}{"JSON.CLEAR", key, path}
cmd := NewIntCmd(ctx, args...)
_ = c(ctx, cmd)
return cmd
}
// JSONDebugMemory reports a value's memory usage in bytes (unimplemented)
// For more information, see https://redis.io/commands/json.debug-memory
func (c cmdable) JSONDebugMemory(ctx context.Context, key, path string) *IntCmd {
panic("not implemented")
}
// JSONDel deletes a value.
// For more information, see https://redis.io/commands/json.del
func (c cmdable) JSONDel(ctx context.Context, key, path string) *IntCmd {
args := []interface{}{"JSON.DEL", key, path}
cmd := NewIntCmd(ctx, args...)
_ = c(ctx, cmd)
return cmd
}
// JSONForget deletes a value.
// For more information, see https://redis.io/commands/json.forget
func (c cmdable) JSONForget(ctx context.Context, key, path string) *IntCmd {
args := []interface{}{"JSON.FORGET", key, path}
cmd := NewIntCmd(ctx, args...)
_ = c(ctx, cmd)
return cmd
}
// JSONGet returns the value at path in JSON serialized form. JSON.GET returns an
// array of strings. This function parses out the wrapping array but leaves the
// internal strings unprocessed by default (see Val())
// For more information - https://redis.io/commands/json.get/
func (c cmdable) JSONGet(ctx context.Context, key string, paths ...string) *JSONCmd {
args := make([]interface{}, len(paths)+2)
args[0] = "JSON.GET"
args[1] = key
for n, path := range paths {
args[n+2] = path
}
cmd := newJSONCmd(ctx, args...)
_ = c(ctx, cmd)
return cmd
}
type JSONGetArgs struct {
Indent string
Newline string
Space string
}
// JSONGetWithArgs - Retrieves the value of a key from a JSON document.
// This function also allows for specifying additional options such as:
// Indention, NewLine and Space
// For more information - https://redis.io/commands/json.get/
func (c cmdable) JSONGetWithArgs(ctx context.Context, key string, options *JSONGetArgs, paths ...string) *JSONCmd {
args := []interface{}{"JSON.GET", key}
if options != nil {
if options.Indent != "" {
args = append(args, "INDENT", options.Indent)
}
if options.Newline != "" {
args = append(args, "NEWLINE", options.Newline)
}
if options.Space != "" {
args = append(args, "SPACE", options.Space)
}
for _, path := range paths {
args = append(args, path)
}
}
cmd := newJSONCmd(ctx, args...)
_ = c(ctx, cmd)
return cmd
}
// JSONMerge merges a given JSON value into matching paths.
// For more information, see https://redis.io/commands/json.merge
func (c cmdable) JSONMerge(ctx context.Context, key, path string, value string) *StatusCmd {
args := []interface{}{"JSON.MERGE", key, path, value}
cmd := NewStatusCmd(ctx, args...)
_ = c(ctx, cmd)
return cmd
}
// JSONMGet returns the values at the specified path from multiple key arguments.
// Note - the arguments are reversed when compared with `JSON.MGET` as we want
// to follow the pattern of having the last argument be variable.
// For more information, see https://redis.io/commands/json.mget
func (c cmdable) JSONMGet(ctx context.Context, path string, keys ...string) *JSONSliceCmd {
args := make([]interface{}, len(keys)+1)
args[0] = "JSON.MGET"
for n, key := range keys {
args[n+1] = key
}
args = append(args, path)
cmd := NewJSONSliceCmd(ctx, args...)
_ = c(ctx, cmd)
return cmd
}
// JSONMSetArgs sets or updates one or more JSON values according to the specified key-path-value triplets.
// For more information, see https://redis.io/commands/json.mset
func (c cmdable) JSONMSetArgs(ctx context.Context, docs []JSONSetArgs) *StatusCmd {
args := []interface{}{"JSON.MSET"}
for _, doc := range docs {
args = append(args, doc.Key, doc.Path, doc.Value)
}
cmd := NewStatusCmd(ctx, args...)
_ = c(ctx, cmd)
return cmd
}
func (c cmdable) JSONMSet(ctx context.Context, params ...interface{}) *StatusCmd {
args := []interface{}{"JSON.MSET"}
args = append(args, params...)
cmd := NewStatusCmd(ctx, args...)
_ = c(ctx, cmd)
return cmd
}
// JSONNumIncrBy increments the number value stored at the specified path by the provided number.
// For more information, see https://redis.io/commands/json.numincreby
func (c cmdable) JSONNumIncrBy(ctx context.Context, key, path string, value float64) *JSONCmd {
args := []interface{}{"JSON.NUMINCRBY", key, path, value}
cmd := newJSONCmd(ctx, args...)
_ = c(ctx, cmd)
return cmd
}
// JSONObjKeys returns the keys in the object that's referenced by the specified path.
// For more information, see https://redis.io/commands/json.objkeys
func (c cmdable) JSONObjKeys(ctx context.Context, key, path string) *SliceCmd {
args := []interface{}{"JSON.OBJKEYS", key, path}
cmd := NewSliceCmd(ctx, args...)
_ = c(ctx, cmd)
return cmd
}
// JSONObjLen reports the number of keys in the JSON object at the specified path in the given key.
// For more information, see https://redis.io/commands/json.objlen
func (c cmdable) JSONObjLen(ctx context.Context, key, path string) *IntPointerSliceCmd {
args := []interface{}{"JSON.OBJLEN", key, path}
cmd := NewIntPointerSliceCmd(ctx, args...)
_ = c(ctx, cmd)
return cmd
}
// JSONSet sets the JSON value at the given path in the given key. The value must be something that
// can be marshaled to JSON (using encoding/JSON) unless the argument is a string or a []byte when we assume that
// it can be passed directly as JSON.
// For more information, see https://redis.io/commands/json.set
func (c cmdable) JSONSet(ctx context.Context, key, path string, value interface{}) *StatusCmd {
return c.JSONSetMode(ctx, key, path, value, "")
}
// JSONSetMode sets the JSON value at the given path in the given key and allows the mode to be set
// (the mode value must be "XX" or "NX"). The value must be something that can be marshaled to JSON (using encoding/JSON) unless
// the argument is a string or []byte when we assume that it can be passed directly as JSON.
// For more information, see https://redis.io/commands/json.set
func (c cmdable) JSONSetMode(ctx context.Context, key, path string, value interface{}, mode string) *StatusCmd {
var bytes []byte
var err error
switch v := value.(type) {
case string:
bytes = []byte(v)
case []byte:
bytes = v
default:
bytes, err = json.Marshal(v)
}
args := []interface{}{"JSON.SET", key, path, util.BytesToString(bytes)}
if mode != "" {
switch strings.ToUpper(mode) {
case "XX", "NX":
args = append(args, strings.ToUpper(mode))
default:
panic("redis: JSON.SET mode must be NX or XX")
}
}
cmd := NewStatusCmd(ctx, args...)
if err != nil {
cmd.SetErr(err)
} else {
_ = c(ctx, cmd)
}
return cmd
}
// JSONStrAppend appends the JSON-string values to the string at the specified path.
// For more information, see https://redis.io/commands/json.strappend
func (c cmdable) JSONStrAppend(ctx context.Context, key, path, value string) *IntPointerSliceCmd {
args := []interface{}{"JSON.STRAPPEND", key, path, value}
cmd := NewIntPointerSliceCmd(ctx, args...)
_ = c(ctx, cmd)
return cmd
}
// JSONStrLen reports the length of the JSON String at the specified path in the given key.
// For more information, see https://redis.io/commands/json.strlen
func (c cmdable) JSONStrLen(ctx context.Context, key, path string) *IntPointerSliceCmd {
args := []interface{}{"JSON.STRLEN", key, path}
cmd := NewIntPointerSliceCmd(ctx, args...)
_ = c(ctx, cmd)
return cmd
}
// JSONToggle toggles a Boolean value stored at the specified path.
// For more information, see https://redis.io/commands/json.toggle
func (c cmdable) JSONToggle(ctx context.Context, key, path string) *IntPointerSliceCmd {
args := []interface{}{"JSON.TOGGLE", key, path}
cmd := NewIntPointerSliceCmd(ctx, args...)
_ = c(ctx, cmd)
return cmd
}
// JSONType reports the type of JSON value at the specified path.
// For more information, see https://redis.io/commands/json.type
func (c cmdable) JSONType(ctx context.Context, key, path string) *JSONSliceCmd {
args := []interface{}{"JSON.TYPE", key, path}
cmd := NewJSONSliceCmd(ctx, args...)
_ = c(ctx, cmd)
return cmd
}

660
json_test.go Normal file
View File

@ -0,0 +1,660 @@
package redis_test
import (
"context"
. "github.com/bsm/ginkgo/v2"
. "github.com/bsm/gomega"
"github.com/redis/go-redis/v9"
)
type JSONGetTestStruct struct {
Hello string `json:"hello"`
}
var _ = Describe("JSON Commands", Label("json"), func() {
ctx := context.TODO()
var client *redis.Client
BeforeEach(func() {
client = redis.NewClient(&redis.Options{Addr: ":6379"})
Expect(client.FlushAll(ctx).Err()).NotTo(HaveOccurred())
})
AfterEach(func() {
Expect(client.Close()).NotTo(HaveOccurred())
})
Describe("arrays", Label("arrays"), func() {
It("should JSONArrAppend", Label("json.arrappend", "json"), func() {
cmd1 := client.JSONSet(ctx, "append2", "$", `{"a": [10], "b": {"a": [12, 13]}}`)
Expect(cmd1.Err()).NotTo(HaveOccurred())
Expect(cmd1.Val()).To(Equal("OK"))
cmd2 := client.JSONArrAppend(ctx, "append2", "$..a", 10)
Expect(cmd2.Err()).NotTo(HaveOccurred())
Expect(cmd2.Val()).To(Equal([]int64{2, 3}))
})
It("should JSONArrIndex and JSONArrIndexWithArgs", Label("json.arrindex", "json"), func() {
cmd1, err := client.JSONSet(ctx, "index1", "$", `{"a": [10], "b": {"a": [12, 10]}}`).Result()
Expect(err).NotTo(HaveOccurred())
Expect(cmd1).To(Equal("OK"))
cmd2, err := client.JSONArrIndex(ctx, "index1", "$.b.a", 10).Result()
Expect(err).NotTo(HaveOccurred())
Expect(cmd2).To(Equal([]int64{1}))
cmd3, err := client.JSONSet(ctx, "index2", "$", `[0,1,2,3,4]`).Result()
Expect(err).NotTo(HaveOccurred())
Expect(cmd3).To(Equal("OK"))
res, err := client.JSONArrIndex(ctx, "index2", "$", 1).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res[0]).To(Equal(int64(1)))
res, err = client.JSONArrIndex(ctx, "index2", "$", 1, 2).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res[0]).To(Equal(int64(-1)))
res, err = client.JSONArrIndex(ctx, "index2", "$", 4).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res[0]).To(Equal(int64(4)))
res, err = client.JSONArrIndexWithArgs(ctx, "index2", "$", &redis.JSONArrIndexArgs{}, 4).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res[0]).To(Equal(int64(4)))
stop := 5000
res, err = client.JSONArrIndexWithArgs(ctx, "index2", "$", &redis.JSONArrIndexArgs{Stop: &stop}, 4).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res[0]).To(Equal(int64(4)))
stop = -1
res, err = client.JSONArrIndexWithArgs(ctx, "index2", "$", &redis.JSONArrIndexArgs{Stop: &stop}, 4).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res[0]).To(Equal(int64(-1)))
})
It("should JSONArrIndex and JSONArrIndexWithArgs with $", Label("json.arrindex", "json"), func() {
doc := `{
"store": {
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95,
"size": [10, 20, 30, 40]
},
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99,
"size": [50, 60, 70, 80]
},
{
"category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99,
"size": [5, 10, 20, 30]
},
{
"category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99,
"size": [5, 6, 7, 8]
}
],
"bicycle": {"color": "red", "price": 19.95}
}
}`
res, err := client.JSONSet(ctx, "doc1", "$", doc).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal("OK"))
resGet, err := client.JSONGet(ctx, "doc1", "$.store.book[?(@.price<10)].size").Result()
Expect(err).NotTo(HaveOccurred())
Expect(resGet).To(Equal("[[10,20,30,40],[5,10,20,30]]"))
resArr, err := client.JSONArrIndex(ctx, "doc1", "$.store.book[?(@.price<10)].size", 20).Result()
Expect(err).NotTo(HaveOccurred())
Expect(resArr).To(Equal([]int64{1, 2}))
})
It("should JSONArrInsert", Label("json.arrinsert", "json"), func() {
cmd1 := client.JSONSet(ctx, "insert2", "$", `[100, 200, 300, 200]`)
Expect(cmd1.Err()).NotTo(HaveOccurred())
Expect(cmd1.Val()).To(Equal("OK"))
cmd2 := client.JSONArrInsert(ctx, "insert2", "$", -1, 1, 2)
Expect(cmd2.Err()).NotTo(HaveOccurred())
Expect(cmd2.Val()).To(Equal([]int64{6}))
cmd3 := client.JSONGet(ctx, "insert2")
Expect(cmd3.Err()).NotTo(HaveOccurred())
// RESP2 vs RESP3
Expect(cmd3.Val()).To(Or(
Equal(`[100,200,300,1,2,200]`),
Equal(`[[100,200,300,1,2,200]]`)))
})
It("should JSONArrLen", Label("json.arrlen", "json"), func() {
cmd1 := client.JSONSet(ctx, "length2", "$", `{"a": [10], "b": {"a": [12, 10, 20, 12, 90, 10]}}`)
Expect(cmd1.Err()).NotTo(HaveOccurred())
Expect(cmd1.Val()).To(Equal("OK"))
cmd2 := client.JSONArrLen(ctx, "length2", "$..a")
Expect(cmd2.Err()).NotTo(HaveOccurred())
Expect(cmd2.Val()).To(Equal([]int64{1, 6}))
})
It("should JSONArrPop", Label("json.arrpop"), func() {
cmd1 := client.JSONSet(ctx, "pop4", "$", `[100, 200, 300, 200]`)
Expect(cmd1.Err()).NotTo(HaveOccurred())
Expect(cmd1.Val()).To(Equal("OK"))
cmd2 := client.JSONArrPop(ctx, "pop4", "$", 2)
Expect(cmd2.Err()).NotTo(HaveOccurred())
Expect(cmd2.Val()).To(Equal([]string{"300"}))
cmd3 := client.JSONGet(ctx, "pop4", "$")
Expect(cmd3.Err()).NotTo(HaveOccurred())
Expect(cmd3.Val()).To(Equal("[[100,200,200]]"))
})
It("should JSONArrTrim", Label("json.arrtrim", "json"), func() {
cmd1, err := client.JSONSet(ctx, "trim1", "$", `[0,1,2,3,4]`).Result()
Expect(err).NotTo(HaveOccurred())
Expect(cmd1).To(Equal("OK"))
stop := 3
cmd2, err := client.JSONArrTrimWithArgs(ctx, "trim1", "$", &redis.JSONArrTrimArgs{Start: 1, Stop: &stop}).Result()
Expect(err).NotTo(HaveOccurred())
Expect(cmd2).To(Equal([]int64{3}))
res, err := client.JSONGet(ctx, "trim1", "$").Result()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal(`[[1,2,3]]`))
cmd3, err := client.JSONSet(ctx, "trim2", "$", `[0,1,2,3,4]`).Result()
Expect(err).NotTo(HaveOccurred())
Expect(cmd3).To(Equal("OK"))
stop = 3
cmd4, err := client.JSONArrTrimWithArgs(ctx, "trim2", "$", &redis.JSONArrTrimArgs{Start: -1, Stop: &stop}).Result()
Expect(err).NotTo(HaveOccurred())
Expect(cmd4).To(Equal([]int64{0}))
cmd5, err := client.JSONSet(ctx, "trim3", "$", `[0,1,2,3,4]`).Result()
Expect(err).NotTo(HaveOccurred())
Expect(cmd5).To(Equal("OK"))
stop = 99
cmd6, err := client.JSONArrTrimWithArgs(ctx, "trim3", "$", &redis.JSONArrTrimArgs{Start: 3, Stop: &stop}).Result()
Expect(err).NotTo(HaveOccurred())
Expect(cmd6).To(Equal([]int64{2}))
cmd7, err := client.JSONSet(ctx, "trim4", "$", `[0,1,2,3,4]`).Result()
Expect(err).NotTo(HaveOccurred())
Expect(cmd7).To(Equal("OK"))
stop = 1
cmd8, err := client.JSONArrTrimWithArgs(ctx, "trim4", "$", &redis.JSONArrTrimArgs{Start: 9, Stop: &stop}).Result()
Expect(err).NotTo(HaveOccurred())
Expect(cmd8).To(Equal([]int64{0}))
cmd9, err := client.JSONSet(ctx, "trim5", "$", `[0,1,2,3,4]`).Result()
Expect(err).NotTo(HaveOccurred())
Expect(cmd9).To(Equal("OK"))
stop = 11
cmd10, err := client.JSONArrTrimWithArgs(ctx, "trim5", "$", &redis.JSONArrTrimArgs{Start: 9, Stop: &stop}).Result()
Expect(err).NotTo(HaveOccurred())
Expect(cmd10).To(Equal([]int64{0}))
})
It("should JSONArrPop", Label("json.arrpop", "json"), func() {
cmd1 := client.JSONSet(ctx, "pop4", "$", `[100, 200, 300, 200]`)
Expect(cmd1.Err()).NotTo(HaveOccurred())
Expect(cmd1.Val()).To(Equal("OK"))
cmd2 := client.JSONArrPop(ctx, "pop4", "$", 2)
Expect(cmd2.Err()).NotTo(HaveOccurred())
Expect(cmd2.Val()).To(Equal([]string{"300"}))
cmd3 := client.JSONGet(ctx, "pop4", "$")
Expect(cmd3.Err()).NotTo(HaveOccurred())
Expect(cmd3.Val()).To(Equal("[[100,200,200]]"))
})
})
Describe("get/set", Label("getset"), func() {
It("should JSONSet", Label("json.set", "json"), func() {
cmd := client.JSONSet(ctx, "set1", "$", `{"a": 1, "b": 2, "hello": "world"}`)
Expect(cmd.Err()).NotTo(HaveOccurred())
Expect(cmd.Val()).To(Equal("OK"))
})
It("should JSONGet", Label("json.get", "json"), func() {
res, err := client.JSONSet(ctx, "get3", "$", `{"a": 1, "b": 2}`).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal("OK"))
res, err = client.JSONGetWithArgs(ctx, "get3", &redis.JSONGetArgs{Indent: "-"}).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal(`[-{--"a":1,--"b":2-}]`))
res, err = client.JSONGetWithArgs(ctx, "get3", &redis.JSONGetArgs{Indent: "-", Newline: `~`, Space: `!`}).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal(`[~-{~--"a":!1,~--"b":!2~-}~]`))
})
It("should JSONMerge", Label("json.merge", "json"), func() {
res, err := client.JSONSet(ctx, "merge1", "$", `{"a": 1, "b": 2}`).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal("OK"))
res, err = client.JSONMerge(ctx, "merge1", "$", `{"b": 3, "c": 4}`).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal("OK"))
res, err = client.JSONGet(ctx, "merge1", "$").Result()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal(`[{"a":1,"b":3,"c":4}]`))
})
It("should JSONMSet", Label("json.mset", "json", "NonRedisEnterprise"), func() {
doc1 := redis.JSONSetArgs{Key: "mset1", Path: "$", Value: `{"a": 1}`}
doc2 := redis.JSONSetArgs{Key: "mset2", Path: "$", Value: 2}
docs := []redis.JSONSetArgs{doc1, doc2}
mSetResult, err := client.JSONMSetArgs(ctx, docs).Result()
Expect(err).NotTo(HaveOccurred())
Expect(mSetResult).To(Equal("OK"))
res, err := client.JSONMGet(ctx, "$", "mset1").Result()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal([]interface{}{`[{"a":1}]`}))
res, err = client.JSONMGet(ctx, "$", "mset1", "mset2").Result()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal([]interface{}{`[{"a":1}]`, "[2]"}))
_, err = client.JSONMSet(ctx, "mset1", "$.a", 2, "mset3", "$", `[1]`).Result()
Expect(err).NotTo(HaveOccurred())
})
It("should JSONMGet", Label("json.mget", "json", "NonRedisEnterprise"), func() {
cmd1 := client.JSONSet(ctx, "mget2a", "$", `{"a": ["aa", "ab", "ac", "ad"], "b": {"a": ["ba", "bb", "bc", "bd"]}}`)
Expect(cmd1.Err()).NotTo(HaveOccurred())
Expect(cmd1.Val()).To(Equal("OK"))
cmd2 := client.JSONSet(ctx, "mget2b", "$", `{"a": [100, 200, 300, 200], "b": {"a": [100, 200, 300, 200]}}`)
Expect(cmd2.Err()).NotTo(HaveOccurred())
Expect(cmd2.Val()).To(Equal("OK"))
cmd3 := client.JSONMGet(ctx, "$..a", "mget2a", "mget2b")
Expect(cmd3.Err()).NotTo(HaveOccurred())
Expect(cmd3.Val()).To(HaveLen(2))
Expect(cmd3.Val()[0]).To(Equal(`[["aa","ab","ac","ad"],["ba","bb","bc","bd"]]`))
Expect(cmd3.Val()[1]).To(Equal(`[[100,200,300,200],[100,200,300,200]]`))
})
It("should JSONMget with $", Label("json.mget", "json", "NonRedisEnterprise"), func() {
res, err := client.JSONSet(ctx, "doc1", "$", `{"a": 1, "b": 2, "nested": {"a": 3}, "c": "", "nested2": {"a": ""}}`).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal("OK"))
res, err = client.JSONSet(ctx, "doc2", "$", `{"a": 4, "b": 5, "nested": {"a": 6}, "c": "", "nested2": {"a": [""]}}`).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal("OK"))
iRes, err := client.JSONMGet(ctx, "$..a", "doc1").Result()
Expect(err).NotTo(HaveOccurred())
Expect(iRes).To(Equal([]interface{}{`[1,3,""]`}))
iRes, err = client.JSONMGet(ctx, "$..a", "doc1", "doc2").Result()
Expect(err).NotTo(HaveOccurred())
Expect(iRes).To(Equal([]interface{}{`[1,3,""]`, `[4,6,[""]]`}))
iRes, err = client.JSONMGet(ctx, "$..a", "non_existing_doc", "non_existing_doc1").Result()
Expect(err).NotTo(HaveOccurred())
Expect(iRes).To(Equal([]interface{}{nil, nil}))
})
})
Describe("Misc", Label("misc"), func() {
It("should JSONClear", Label("json.clear", "json"), func() {
cmd1 := client.JSONSet(ctx, "clear1", "$", `[1]`)
Expect(cmd1.Err()).NotTo(HaveOccurred())
Expect(cmd1.Val()).To(Equal("OK"))
cmd2 := client.JSONClear(ctx, "clear1", "$")
Expect(cmd2.Err()).NotTo(HaveOccurred())
Expect(cmd2.Val()).To(Equal(int64(1)))
cmd3 := client.JSONGet(ctx, "clear1", "$")
Expect(cmd3.Err()).NotTo(HaveOccurred())
Expect(cmd3.Val()).To(Equal(`[[]]`))
})
It("should JSONClear with $", Label("json.clear", "json"), func() {
doc := `{
"nested1": {"a": {"foo": 10, "bar": 20}},
"a": ["foo"],
"nested2": {"a": "claro"},
"nested3": {"a": {"baz": 50}}
}`
res, err := client.JSONSet(ctx, "doc1", "$", doc).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal("OK"))
iRes, err := client.JSONClear(ctx, "doc1", "$..a").Result()
Expect(err).NotTo(HaveOccurred())
Expect(iRes).To(Equal(int64(3)))
resGet, err := client.JSONGet(ctx, "doc1", `$`).Result()
Expect(err).NotTo(HaveOccurred())
Expect(resGet).To(Equal(`[{"nested1":{"a":{}},"a":[],"nested2":{"a":"claro"},"nested3":{"a":{}}}]`))
res, err = client.JSONSet(ctx, "doc1", "$", doc).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal("OK"))
iRes, err = client.JSONClear(ctx, "doc1", "$.nested1.a").Result()
Expect(err).NotTo(HaveOccurred())
Expect(iRes).To(Equal(int64(1)))
resGet, err = client.JSONGet(ctx, "doc1", `$`).Result()
Expect(err).NotTo(HaveOccurred())
Expect(resGet).To(Equal(`[{"nested1":{"a":{}},"a":["foo"],"nested2":{"a":"claro"},"nested3":{"a":{"baz":50}}}]`))
})
It("should JSONDel", Label("json.del", "json"), func() {
cmd1 := client.JSONSet(ctx, "del1", "$", `[1]`)
Expect(cmd1.Err()).NotTo(HaveOccurred())
Expect(cmd1.Val()).To(Equal("OK"))
cmd2 := client.JSONDel(ctx, "del1", "$")
Expect(cmd2.Err()).NotTo(HaveOccurred())
Expect(cmd2.Val()).To(Equal(int64(1)))
cmd3 := client.JSONGet(ctx, "del1", "$")
Expect(cmd3.Err()).NotTo(HaveOccurred())
Expect(cmd3.Val()).To(HaveLen(0))
})
It("should JSONDel with $", Label("json.del", "json"), func() {
res, err := client.JSONSet(ctx, "del1", "$", `{"a": 1, "nested": {"a": 2, "b": 3}}`).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal("OK"))
iRes, err := client.JSONDel(ctx, "del1", "$..a").Result()
Expect(err).NotTo(HaveOccurred())
Expect(iRes).To(Equal(int64(2)))
resGet, err := client.JSONGet(ctx, "del1", "$").Result()
Expect(err).NotTo(HaveOccurred())
Expect(resGet).To(Equal(`[{"nested":{"b":3}}]`))
res, err = client.JSONSet(ctx, "del2", "$", `{"a": {"a": 2, "b": 3}, "b": ["a", "b"], "nested": {"b": [true, "a", "b"]}}`).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal("OK"))
iRes, err = client.JSONDel(ctx, "del2", "$..a").Result()
Expect(err).NotTo(HaveOccurred())
Expect(iRes).To(Equal(int64(1)))
resGet, err = client.JSONGet(ctx, "del2", "$").Result()
Expect(err).NotTo(HaveOccurred())
Expect(resGet).To(Equal(`[{"nested":{"b":[true,"a","b"]},"b":["a","b"]}]`))
doc := `[
{
"ciao": ["non ancora"],
"nested": [
{"ciao": [1, "a"]},
{"ciao": [2, "a"]},
{"ciaoc": [3, "non", "ciao"]},
{"ciao": [4, "a"]},
{"e": [5, "non", "ciao"]}
]
}
]`
res, err = client.JSONSet(ctx, "del3", "$", doc).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal("OK"))
iRes, err = client.JSONDel(ctx, "del3", `$.[0]["nested"]..ciao`).Result()
Expect(err).NotTo(HaveOccurred())
Expect(iRes).To(Equal(int64(3)))
resVal := `[[{"ciao":["non ancora"],"nested":[{},{},{"ciaoc":[3,"non","ciao"]},{},{"e":[5,"non","ciao"]}]}]]`
resGet, err = client.JSONGet(ctx, "del3", "$").Result()
Expect(err).NotTo(HaveOccurred())
Expect(resGet).To(Equal(resVal))
})
It("should JSONForget", Label("json.forget", "json"), func() {
cmd1 := client.JSONSet(ctx, "forget3", "$", `{"a": [1,2,3], "b": {"a": [1,2,3], "b": "annie"}}`)
Expect(cmd1.Err()).NotTo(HaveOccurred())
Expect(cmd1.Val()).To(Equal("OK"))
cmd2 := client.JSONForget(ctx, "forget3", "$..a")
Expect(cmd2.Err()).NotTo(HaveOccurred())
Expect(cmd2.Val()).To(Equal(int64(2)))
cmd3 := client.JSONGet(ctx, "forget3", "$")
Expect(cmd3.Err()).NotTo(HaveOccurred())
Expect(cmd3.Val()).To(Equal(`[{"b":{"b":"annie"}}]`))
})
It("should JSONForget with $", Label("json.forget", "json"), func() {
res, err := client.JSONSet(ctx, "doc1", "$", `{"a": 1, "nested": {"a": 2, "b": 3}}`).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal("OK"))
iRes, err := client.JSONForget(ctx, "doc1", "$..a").Result()
Expect(err).NotTo(HaveOccurred())
Expect(iRes).To(Equal(int64(2)))
resGet, err := client.JSONGet(ctx, "doc1", "$").Result()
Expect(err).NotTo(HaveOccurred())
Expect(resGet).To(Equal(`[{"nested":{"b":3}}]`))
res, err = client.JSONSet(ctx, "doc2", "$", `{"a": {"a": 2, "b": 3}, "b": ["a", "b"], "nested": {"b": [true, "a", "b"]}}`).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal("OK"))
iRes, err = client.JSONForget(ctx, "doc2", "$..a").Result()
Expect(err).NotTo(HaveOccurred())
Expect(iRes).To(Equal(int64(1)))
resGet, err = client.JSONGet(ctx, "doc2", "$").Result()
Expect(err).NotTo(HaveOccurred())
Expect(resGet).To(Equal(`[{"nested":{"b":[true,"a","b"]},"b":["a","b"]}]`))
doc := `[
{
"ciao": ["non ancora"],
"nested": [
{"ciao": [1, "a"]},
{"ciao": [2, "a"]},
{"ciaoc": [3, "non", "ciao"]},
{"ciao": [4, "a"]},
{"e": [5, "non", "ciao"]}
]
}
]`
res, err = client.JSONSet(ctx, "doc3", "$", doc).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal("OK"))
iRes, err = client.JSONForget(ctx, "doc3", `$.[0]["nested"]..ciao`).Result()
Expect(err).NotTo(HaveOccurred())
Expect(iRes).To(Equal(int64(3)))
resVal := `[[{"ciao":["non ancora"],"nested":[{},{},{"ciaoc":[3,"non","ciao"]},{},{"e":[5,"non","ciao"]}]}]]`
resGet, err = client.JSONGet(ctx, "doc3", "$").Result()
Expect(err).NotTo(HaveOccurred())
Expect(resGet).To(Equal(resVal))
})
It("should JSONNumIncrBy", Label("json.numincrby", "json"), func() {
cmd1 := client.JSONSet(ctx, "incr3", "$", `{"a": [1, 2], "b": {"a": [0, -1]}}`)
Expect(cmd1.Err()).NotTo(HaveOccurred())
Expect(cmd1.Val()).To(Equal("OK"))
cmd2 := client.JSONNumIncrBy(ctx, "incr3", "$..a[1]", float64(1))
Expect(cmd2.Err()).NotTo(HaveOccurred())
Expect(cmd2.Val()).To(Equal(`[3,0]`))
})
It("should JSONNumIncrBy with $", Label("json.numincrby", "json"), func() {
res, err := client.JSONSet(ctx, "doc1", "$", `{"a": "b", "b": [{"a": 2}, {"a": 5.0}, {"a": "c"}]}`).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal("OK"))
res, err = client.JSONNumIncrBy(ctx, "doc1", "$.b[1].a", 2).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal(`[7]`))
res, err = client.JSONNumIncrBy(ctx, "doc1", "$.b[1].a", 3.5).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal(`[10.5]`))
res, err = client.JSONSet(ctx, "doc2", "$", `{"a": "b", "b": [{"a": 2}, {"a": 5.0}, {"a": "c"}]}`).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal("OK"))
res, err = client.JSONNumIncrBy(ctx, "doc2", "$.b[0].a", 3).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal(`[5]`))
})
It("should JSONObjKeys", Label("json.objkeys", "json"), func() {
cmd1 := client.JSONSet(ctx, "objkeys1", "$", `{"a": [1, 2], "b": {"a": [0, -1]}}`)
Expect(cmd1.Err()).NotTo(HaveOccurred())
Expect(cmd1.Val()).To(Equal("OK"))
cmd2 := client.JSONObjKeys(ctx, "objkeys1", "$..*")
Expect(cmd2.Err()).NotTo(HaveOccurred())
Expect(cmd2.Val()).To(HaveLen(7))
Expect(cmd2.Val()).To(Equal([]interface{}{nil, []interface{}{"a"}, nil, nil, nil, nil, nil}))
})
It("should JSONObjKeys with $", Label("json.objkeys", "json"), func() {
doc := `{
"nested1": {"a": {"foo": 10, "bar": 20}},
"a": ["foo"],
"nested2": {"a": {"baz": 50}}
}`
cmd1, err := client.JSONSet(ctx, "objkeys1", "$", doc).Result()
Expect(err).NotTo(HaveOccurred())
Expect(cmd1).To(Equal("OK"))
cmd2, err := client.JSONObjKeys(ctx, "objkeys1", "$.nested1.a").Result()
Expect(err).NotTo(HaveOccurred())
Expect(cmd2).To(Equal([]interface{}{[]interface{}{"foo", "bar"}}))
cmd2, err = client.JSONObjKeys(ctx, "objkeys1", ".*.a").Result()
Expect(err).NotTo(HaveOccurred())
Expect(cmd2).To(Equal([]interface{}{"foo", "bar"}))
cmd2, err = client.JSONObjKeys(ctx, "objkeys1", ".nested2.a").Result()
Expect(err).NotTo(HaveOccurred())
Expect(cmd2).To(Equal([]interface{}{"baz"}))
_, err = client.JSONObjKeys(ctx, "non_existing_doc", "..a").Result()
Expect(err).To(HaveOccurred())
})
It("should JSONObjLen", Label("json.objlen", "json"), func() {
cmd1 := client.JSONSet(ctx, "objlen2", "$", `{"a": [1, 2], "b": {"a": [0, -1]}}`)
Expect(cmd1.Err()).NotTo(HaveOccurred())
Expect(cmd1.Val()).To(Equal("OK"))
cmd2 := client.JSONObjLen(ctx, "objlen2", "$..*")
Expect(cmd2.Err()).NotTo(HaveOccurred())
Expect(cmd2.Val()).To(HaveLen(7))
Expect(cmd2.Val()[0]).To(BeNil())
Expect(*cmd2.Val()[1]).To(Equal(int64(1)))
})
It("should JSONStrLen", Label("json.strlen", "json"), func() {
cmd1 := client.JSONSet(ctx, "strlen2", "$", `{"a": "alice", "b": "bob", "c": {"a": "alice", "b": "bob"}}`)
Expect(cmd1.Err()).NotTo(HaveOccurred())
Expect(cmd1.Val()).To(Equal("OK"))
cmd2 := client.JSONStrLen(ctx, "strlen2", "$..*")
Expect(cmd2.Err()).NotTo(HaveOccurred())
Expect(cmd2.Val()).To(HaveLen(5))
var tmp int64 = 20
Expect(cmd2.Val()[0]).To(BeAssignableToTypeOf(&tmp))
Expect(*cmd2.Val()[0]).To(Equal(int64(5)))
Expect(*cmd2.Val()[1]).To(Equal(int64(3)))
Expect(cmd2.Val()[2]).To(BeNil())
Expect(*cmd2.Val()[3]).To(Equal(int64(5)))
Expect(*cmd2.Val()[4]).To(Equal(int64(3)))
})
It("should JSONStrAppend", Label("json.strappend", "json"), func() {
cmd1, err := client.JSONSet(ctx, "strapp1", "$", `"foo"`).Result()
Expect(err).NotTo(HaveOccurred())
Expect(cmd1).To(Equal("OK"))
cmd2, err := client.JSONStrAppend(ctx, "strapp1", "$", `"bar"`).Result()
Expect(err).NotTo(HaveOccurred())
Expect(*cmd2[0]).To(Equal(int64(6)))
cmd3, err := client.JSONGet(ctx, "strapp1", "$").Result()
Expect(err).NotTo(HaveOccurred())
Expect(cmd3).To(Equal(`["foobar"]`))
})
It("should JSONStrAppend and JSONStrLen with $", Label("json.strappend", "json.strlen", "json"), func() {
res, err := client.JSONSet(ctx, "doc1", "$", `{"a": "foo", "nested1": {"a": "hello"}, "nested2": {"a": 31}}`).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal("OK"))
intArrayResult, err := client.JSONStrAppend(ctx, "doc1", "$.nested1.a", `"baz"`).Result()
Expect(err).NotTo(HaveOccurred())
Expect(*intArrayResult[0]).To(Equal(int64(8)))
res, err = client.JSONSet(ctx, "doc2", "$", `{"a": "foo", "nested1": {"a": "hello"}, "nested2": {"a": 31}}`).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal("OK"))
intResult, err := client.JSONStrLen(ctx, "doc2", "$.nested1.a").Result()
Expect(err).NotTo(HaveOccurred())
Expect(*intResult[0]).To(Equal(int64(5)))
})
It("should JSONToggle", Label("json.toggle", "json"), func() {
cmd1 := client.JSONSet(ctx, "toggle1", "$", `[true]`)
Expect(cmd1.Err()).NotTo(HaveOccurred())
Expect(cmd1.Val()).To(Equal("OK"))
cmd2 := client.JSONToggle(ctx, "toggle1", "$[0]")
Expect(cmd2.Err()).NotTo(HaveOccurred())
Expect(cmd2.Val()).To(HaveLen(1))
Expect(*cmd2.Val()[0]).To(Equal(int64(0)))
})
It("should JSONType", Label("json.type", "json"), func() {
cmd1 := client.JSONSet(ctx, "type1", "$", `[true]`)
Expect(cmd1.Err()).NotTo(HaveOccurred())
Expect(cmd1.Val()).To(Equal("OK"))
cmd2 := client.JSONType(ctx, "type1", "$[0]")
Expect(cmd2.Err()).NotTo(HaveOccurred())
Expect(cmd2.Val()).To(HaveLen(1))
// RESP2 v RESP3
Expect(cmd2.Val()[0]).To(Or(Equal([]interface{}{"boolean"}), Equal("boolean")))
})
})
})

View File

@ -6,6 +6,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strconv"
"sync"
"testing"
"time"
@ -41,6 +42,11 @@ var (
redisAddr = ":" + redisPort
)
var (
rediStackPort = "6379"
rediStackAddr = ":" + rediStackPort
)
var (
sentinelAddrs = []string{":" + sentinelPort1, ":" + sentinelPort2, ":" + sentinelPort3}
@ -59,6 +65,8 @@ var cluster = &clusterScenario{
clients: make(map[string]*redis.Client, 6),
}
var RECluster = false
func registerProcess(port string, p *redisProcess) {
if processes == nil {
processes = make(map[string]*redisProcess)
@ -73,47 +81,56 @@ var _ = BeforeSuite(func() {
redisAddr = ":" + redisPort
}
var err error
RECluster, _ = strconv.ParseBool(os.Getenv("RE_CLUSTER"))
redisMain, err = startRedis(redisPort)
Expect(err).NotTo(HaveOccurred())
if !RECluster {
ringShard1, err = startRedis(ringShard1Port)
Expect(err).NotTo(HaveOccurred())
redisMain, err = startRedis(redisPort)
Expect(err).NotTo(HaveOccurred())
ringShard2, err = startRedis(ringShard2Port)
Expect(err).NotTo(HaveOccurred())
ringShard1, err = startRedis(ringShard1Port)
Expect(err).NotTo(HaveOccurred())
ringShard3, err = startRedis(ringShard3Port)
Expect(err).NotTo(HaveOccurred())
ringShard2, err = startRedis(ringShard2Port)
Expect(err).NotTo(HaveOccurred())
sentinelMaster, err = startRedis(sentinelMasterPort)
Expect(err).NotTo(HaveOccurred())
ringShard3, err = startRedis(ringShard3Port)
Expect(err).NotTo(HaveOccurred())
sentinel1, err = startSentinel(sentinelPort1, sentinelName, sentinelMasterPort)
Expect(err).NotTo(HaveOccurred())
sentinelMaster, err = startRedis(sentinelMasterPort)
Expect(err).NotTo(HaveOccurred())
sentinel2, err = startSentinel(sentinelPort2, sentinelName, sentinelMasterPort)
Expect(err).NotTo(HaveOccurred())
sentinel1, err = startSentinel(sentinelPort1, sentinelName, sentinelMasterPort)
Expect(err).NotTo(HaveOccurred())
sentinel3, err = startSentinel(sentinelPort3, sentinelName, sentinelMasterPort)
Expect(err).NotTo(HaveOccurred())
sentinel2, err = startSentinel(sentinelPort2, sentinelName, sentinelMasterPort)
Expect(err).NotTo(HaveOccurred())
sentinelSlave1, err = startRedis(
sentinelSlave1Port, "--slaveof", "127.0.0.1", sentinelMasterPort)
Expect(err).NotTo(HaveOccurred())
sentinel3, err = startSentinel(sentinelPort3, sentinelName, sentinelMasterPort)
Expect(err).NotTo(HaveOccurred())
sentinelSlave2, err = startRedis(
sentinelSlave2Port, "--slaveof", "127.0.0.1", sentinelMasterPort)
Expect(err).NotTo(HaveOccurred())
sentinelSlave1, err = startRedis(
sentinelSlave1Port, "--slaveof", "127.0.0.1", sentinelMasterPort)
Expect(err).NotTo(HaveOccurred())
Expect(startCluster(ctx, cluster)).NotTo(HaveOccurred())
sentinelSlave2, err = startRedis(
sentinelSlave2Port, "--slaveof", "127.0.0.1", sentinelMasterPort)
Expect(err).NotTo(HaveOccurred())
Expect(startCluster(ctx, cluster)).NotTo(HaveOccurred())
} else {
redisPort = rediStackPort
redisAddr = rediStackAddr
}
})
var _ = AfterSuite(func() {
Expect(cluster.Close()).NotTo(HaveOccurred())
if !RECluster {
Expect(cluster.Close()).NotTo(HaveOccurred())
for _, p := range processes {
Expect(p.Close()).NotTo(HaveOccurred())
for _, p := range processes {
Expect(p.Close()).NotTo(HaveOccurred())
}
}
processes = nil
})
@ -126,6 +143,23 @@ func TestGinkgoSuite(t *testing.T) {
//------------------------------------------------------------------------------
func redisOptions() *redis.Options {
if RECluster {
return &redis.Options{
Addr: redisAddr,
DB: 0,
DialTimeout: 10 * time.Second,
ReadTimeout: 30 * time.Second,
WriteTimeout: 30 * time.Second,
ContextTimeoutEnabled: true,
MaxRetries: -1,
PoolSize: 10,
PoolTimeout: 30 * time.Second,
ConnMaxIdleTime: time.Minute,
}
}
return &redis.Options{
Addr: redisAddr,
DB: 15,

48
monitor_test.go Normal file
View File

@ -0,0 +1,48 @@
package redis_test
import (
"context"
"time"
. "github.com/bsm/ginkgo/v2"
. "github.com/bsm/gomega"
"github.com/redis/go-redis/v9"
)
var _ = Describe("Monitor command", Label("monitor"), func() {
ctx := context.TODO()
var client *redis.Client
BeforeEach(func() {
client = redis.NewClient(&redis.Options{Addr: ":6379"})
Expect(client.FlushDB(ctx).Err()).NotTo(HaveOccurred())
})
AfterEach(func() {
Expect(client.Close()).NotTo(HaveOccurred())
})
It("should monitor", Label("monitor"), func() {
ress := make(chan string)
client1 := redis.NewClient(&redis.Options{Addr: rediStackAddr})
mn := client1.Monitor(ctx, ress)
mn.Start()
// Wait for the Redis server to be in monitoring mode.
time.Sleep(100 * time.Millisecond)
client.Set(ctx, "foo", "bar", 0)
client.Set(ctx, "bar", "baz", 0)
client.Set(ctx, "bap", 8, 0)
client.Get(ctx, "bap")
lst := []string{}
for i := 0; i < 5; i++ {
s := <-ress
lst = append(lst, s)
}
mn.Stop()
Expect(lst[0]).To(ContainSubstring("OK"))
Expect(lst[1]).To(ContainSubstring(`"set" "foo" "bar"`))
Expect(lst[2]).To(ContainSubstring(`"set" "bar" "baz"`))
Expect(lst[3]).To(ContainSubstring(`"set" "bap" "8"`))
})
})

View File

@ -142,7 +142,7 @@ type Options struct {
// Enables read only queries on slave/follower nodes.
readOnly bool
// // Disable set-lib on connect. Default is false.
// Disable set-lib on connect. Default is false.
DisableIndentity bool
// Hooks are initial hooks in options like AddHook.
@ -464,6 +464,7 @@ func setupConnParams(u *url.URL, o *Options) (*Options, error) {
o.PoolTimeout = q.duration("pool_timeout")
o.MinIdleConns = q.int("min_idle_conns")
o.MaxIdleConns = q.int("max_idle_conns")
o.MaxActiveConns = q.int("max_active_conns")
if q.has("conn_max_idle_time") {
o.ConnMaxIdleTime = q.duration("conn_max_idle_time")
} else {

View File

@ -80,6 +80,7 @@ type ClusterOptions struct {
PoolTimeout time.Duration
MinIdleConns int
MaxIdleConns int
MaxActiveConns int // applies per cluster node and not for the whole cluster
ConnMaxIdleTime time.Duration
ConnMaxLifetime time.Duration
@ -234,6 +235,8 @@ func setupClusterQueryParams(u *url.URL, o *ClusterOptions) (*ClusterOptions, er
o.PoolFIFO = q.bool("pool_fifo")
o.PoolSize = q.int("pool_size")
o.MinIdleConns = q.int("min_idle_conns")
o.MaxIdleConns = q.int("max_idle_conns")
o.MaxActiveConns = q.int("max_active_conns")
o.PoolTimeout = q.duration("pool_timeout")
o.ConnMaxLifetime = q.duration("conn_max_lifetime")
o.ConnMaxIdleTime = q.duration("conn_max_idle_time")
@ -275,15 +278,17 @@ func (opt *ClusterOptions) clientOptions() *Options {
MinRetryBackoff: opt.MinRetryBackoff,
MaxRetryBackoff: opt.MaxRetryBackoff,
DialTimeout: opt.DialTimeout,
ReadTimeout: opt.ReadTimeout,
WriteTimeout: opt.WriteTimeout,
DialTimeout: opt.DialTimeout,
ReadTimeout: opt.ReadTimeout,
WriteTimeout: opt.WriteTimeout,
ContextTimeoutEnabled: opt.ContextTimeoutEnabled,
PoolFIFO: opt.PoolFIFO,
PoolSize: opt.PoolSize,
PoolTimeout: opt.PoolTimeout,
MinIdleConns: opt.MinIdleConns,
MaxIdleConns: opt.MaxIdleConns,
MaxActiveConns: opt.MaxActiveConns,
ConnMaxIdleTime: opt.ConnMaxIdleTime,
ConnMaxLifetime: opt.ConnMaxLifetime,
DisableIndentity: opt.DisableIndentity,
@ -907,7 +912,6 @@ func (c *ClusterClient) Process(ctx context.Context, cmd Cmder) error {
}
func (c *ClusterClient) process(ctx context.Context, cmd Cmder) error {
cmdInfo := c.cmdInfo(ctx, cmd.Name())
slot := c.cmdSlot(ctx, cmd)
var node *clusterNode
var ask bool
@ -921,7 +925,7 @@ func (c *ClusterClient) process(ctx context.Context, cmd Cmder) error {
if node == nil {
var err error
node, err = c.cmdNode(ctx, cmdInfo, slot)
node, err = c.cmdNode(ctx, cmd.Name(), slot)
if err != nil {
return err
}
@ -1783,8 +1787,7 @@ func (c *ClusterClient) cmdSlot(ctx context.Context, cmd Cmder) int {
return args[2].(int)
}
cmdInfo := c.cmdInfo(ctx, cmd.Name())
return cmdSlot(cmd, cmdFirstKeyPos(cmd, cmdInfo))
return cmdSlot(cmd, cmdFirstKeyPos(cmd))
}
func cmdSlot(cmd Cmder, pos int) int {
@ -1797,7 +1800,7 @@ func cmdSlot(cmd Cmder, pos int) int {
func (c *ClusterClient) cmdNode(
ctx context.Context,
cmdInfo *CommandInfo,
cmdName string,
slot int,
) (*clusterNode, error) {
state, err := c.state.Get(ctx)
@ -1805,8 +1808,11 @@ func (c *ClusterClient) cmdNode(
return nil, err
}
if c.opt.ReadOnly && cmdInfo != nil && cmdInfo.ReadOnly {
return c.slotReadOnlyNode(state, slot)
if c.opt.ReadOnly {
cmdInfo := c.cmdInfo(ctx, cmdName)
if cmdInfo != nil && cmdInfo.ReadOnly {
return c.slotReadOnlyNode(state, slot)
}
}
return state.slotMasterNode(slot)
}

View File

@ -1,6 +1,6 @@
{
"name": "redis",
"version": "9.2.1",
"version": "9.3.1",
"main": "index.js",
"repository": "git@github.com:redis/go-redis.git",
"author": "Vladimir Mihailenco <vladimir.webdev@gmail.com>",

View File

@ -71,7 +71,7 @@ var _ = Describe("pipelining", func() {
Expect(cmds).To(HaveLen(1))
})
It("handles large pipelines", func() {
It("handles large pipelines", Label("NonRedisEnterprise"), func() {
for callCount := 1; callCount < 16; callCount++ {
for i := 1; i <= callCount; i++ {
pipe.SetNX(ctx, strconv.Itoa(i)+"_key", strconv.Itoa(i)+"_value", 0)

View File

@ -150,12 +150,7 @@ func (c cmdable) BFReserveNonScaling(ctx context.Context, key string, errorRate
func (c cmdable) BFReserveWithArgs(ctx context.Context, key string, options *BFReserveOptions) *StatusCmd {
args := []interface{}{"BF.RESERVE", key}
if options != nil {
if options.Error != 0 {
args = append(args, options.Error)
}
if options.Capacity != 0 {
args = append(args, options.Capacity)
}
args = append(args, options.Error, options.Capacity)
if options.Expansion != 0 {
args = append(args, "EXPANSION", options.Expansion)
}

View File

@ -460,7 +460,7 @@ var _ = Describe("Probabilistic commands", Label("probabilistic"), func() {
Expect(info).To(BeAssignableToTypeOf(redis.CMSInfo{}))
})
It("should CMSMerge, CMSMergeWithWeight and CMSQuery", Label("cms", "cmsmerge", "cmsquery"), func() {
It("should CMSMerge, CMSMergeWithWeight and CMSQuery", Label("cms", "cmsmerge", "cmsquery", "NonRedisEnterprise"), func() {
err := client.CMSMerge(ctx, "destCms1", "testcms2", "testcms3").Err()
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError("CMS: key does not exist"))
@ -697,7 +697,7 @@ var _ = Describe("Probabilistic commands", Label("probabilistic"), func() {
Expect(info.Compression).To(BeEquivalentTo(int64(2000)))
})
It("should TDigestMerge", Label("tdigest", "tmerge"), func() {
It("should TDigestMerge", Label("tdigest", "tmerge", "NonRedisEnterprise"), func() {
err := client.TDigestCreate(ctx, "tdigest1").Err()
Expect(err).NotTo(HaveOccurred())
err = client.TDigestAdd(ctx, "tdigest1", 10, 20, 30, 40, 50, 60, 70, 80, 90, 100).Err()

View File

@ -487,11 +487,11 @@ func (c *PubSub) getContext() context.Context {
// Channel returns a Go channel for concurrently receiving messages.
// The channel is closed together with the PubSub. If the Go channel
// is blocked full for 30 seconds the message is dropped.
// is blocked full for 1 minute the message is dropped.
// Receive* APIs can not be used after channel is created.
//
// go-redis periodically sends ping messages to test connection health
// and re-subscribes if ping can not not received for 30 seconds.
// and re-subscribes if ping can not not received for 1 minute.
func (c *PubSub) Channel(opts ...ChannelOption) <-chan *Message {
c.chOnce.Do(func() {
c.msgCh = newChannel(c, opts...)

View File

@ -137,7 +137,7 @@ var _ = Describe("races", func() {
})
})
It("should select db", func() {
It("should select db", Label("NonRedisEnterprise"), func() {
err := client.Set(ctx, "db", 1, 0).Err()
Expect(err).NotTo(HaveOccurred())
@ -243,7 +243,7 @@ var _ = Describe("races", func() {
})
})
var _ = Describe("cluster races", func() {
var _ = Describe("cluster races", Label("NonRedisEnterprise"), func() {
var client *redis.ClusterClient
var C, N int

View File

@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"net"
"sync"
"sync/atomic"
"time"
@ -40,12 +41,15 @@ type (
)
type hooksMixin struct {
hooksMu *sync.Mutex
slice []Hook
initial hooks
current hooks
}
func (hs *hooksMixin) initHooks(hooks hooks) {
hs.hooksMu = new(sync.Mutex)
hs.initial = hooks
hs.chain()
}
@ -116,6 +120,9 @@ func (hs *hooksMixin) AddHook(hook Hook) {
func (hs *hooksMixin) chain() {
hs.initial.setDefaults()
hs.hooksMu.Lock()
defer hs.hooksMu.Unlock()
hs.current.dial = hs.initial.dial
hs.current.process = hs.initial.process
hs.current.pipeline = hs.initial.pipeline
@ -138,9 +145,13 @@ func (hs *hooksMixin) chain() {
}
func (hs *hooksMixin) clone() hooksMixin {
hs.hooksMu.Lock()
defer hs.hooksMu.Unlock()
clone := *hs
l := len(clone.slice)
clone.slice = clone.slice[:l:l]
clone.hooksMu = new(sync.Mutex)
return clone
}
@ -165,6 +176,8 @@ func (hs *hooksMixin) withProcessPipelineHook(
}
func (hs *hooksMixin) dialHook(ctx context.Context, network, addr string) (net.Conn, error) {
hs.hooksMu.Lock()
defer hs.hooksMu.Unlock()
return hs.current.dial(ctx, network, addr)
}

View File

@ -65,7 +65,11 @@ var _ = Describe("Client", func() {
})
It("should Stringer", func() {
Expect(client.String()).To(Equal(fmt.Sprintf("Redis<:%s db:15>", redisPort)))
if RECluster {
Expect(client.String()).To(Equal(fmt.Sprintf("Redis<:%s db:0>", redisPort)))
} else {
Expect(client.String()).To(Equal(fmt.Sprintf("Redis<:%s db:15>", redisPort)))
}
})
It("supports context", func() {
@ -76,7 +80,7 @@ var _ = Describe("Client", func() {
Expect(err).To(MatchError("context canceled"))
})
It("supports WithTimeout", func() {
It("supports WithTimeout", Label("NonRedisEnterprise"), func() {
err := client.ClientPause(ctx, time.Second).Err()
Expect(err).NotTo(HaveOccurred())
@ -151,7 +155,7 @@ var _ = Describe("Client", func() {
Expect(pubsub.Close()).NotTo(HaveOccurred())
})
It("should select DB", func() {
It("should select DB", Label("NonRedisEnterprise"), func() {
db2 := redis.NewClient(&redis.Options{
Addr: redisAddr,
DB: 2,
@ -503,7 +507,7 @@ var _ = Describe("Conn", func() {
Expect(err).NotTo(HaveOccurred())
})
It("TxPipeline", func() {
It("TxPipeline", Label("NonRedisEnterprise"), func() {
tx := client.Conn().TxPipeline()
tx.SwapDB(ctx, 0, 2)
tx.SwapDB(ctx, 1, 0)
@ -558,4 +562,74 @@ var _ = Describe("Hook", func() {
"hook-1-process-end",
}))
})
It("wrapped error in a hook", func() {
client.AddHook(&hook{
processHook: func(hook redis.ProcessHook) redis.ProcessHook {
return func(ctx context.Context, cmd redis.Cmder) error {
if err := hook(ctx, cmd); err != nil {
return fmt.Errorf("wrapped error: %w", err)
}
return nil
}
},
})
client.ScriptFlush(ctx)
script := redis.NewScript(`return 'Script and hook'`)
cmd := script.Run(ctx, client, nil)
Expect(cmd.Err()).NotTo(HaveOccurred())
Expect(cmd.Val()).To(Equal("Script and hook"))
})
})
var _ = Describe("Hook with MinIdleConns", func() {
var client *redis.Client
BeforeEach(func() {
options := redisOptions()
options.MinIdleConns = 1
client = redis.NewClient(options)
Expect(client.FlushDB(ctx).Err()).NotTo(HaveOccurred())
})
AfterEach(func() {
err := client.Close()
Expect(err).NotTo(HaveOccurred())
})
It("fifo", func() {
var res []string
client.AddHook(&hook{
processHook: func(hook redis.ProcessHook) redis.ProcessHook {
return func(ctx context.Context, cmd redis.Cmder) error {
res = append(res, "hook-1-process-start")
err := hook(ctx, cmd)
res = append(res, "hook-1-process-end")
return err
}
},
})
client.AddHook(&hook{
processHook: func(hook redis.ProcessHook) redis.ProcessHook {
return func(ctx context.Context, cmd redis.Cmder) error {
res = append(res, "hook-2-process-start")
err := hook(ctx, cmd)
res = append(res, "hook-2-process-end")
return err
}
},
})
err := client.Ping(ctx).Err()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal([]string{
"hook-1-process-start",
"hook-2-process-start",
"hook-2-process-end",
"hook-1-process-end",
}))
})
})

38
ring.go
View File

@ -79,9 +79,10 @@ type RingOptions struct {
MinRetryBackoff time.Duration
MaxRetryBackoff time.Duration
DialTimeout time.Duration
ReadTimeout time.Duration
WriteTimeout time.Duration
DialTimeout time.Duration
ReadTimeout time.Duration
WriteTimeout time.Duration
ContextTimeoutEnabled bool
// PoolFIFO uses FIFO mode for each node connection pool GET/PUT (default LIFO).
PoolFIFO bool
@ -90,11 +91,14 @@ type RingOptions struct {
PoolTimeout time.Duration
MinIdleConns int
MaxIdleConns int
MaxActiveConns int
ConnMaxIdleTime time.Duration
ConnMaxLifetime time.Duration
TLSConfig *tls.Config
Limiter Limiter
DisableIndentity bool
}
func (opt *RingOptions) init() {
@ -144,20 +148,24 @@ func (opt *RingOptions) clientOptions() *Options {
MaxRetries: -1,
DialTimeout: opt.DialTimeout,
ReadTimeout: opt.ReadTimeout,
WriteTimeout: opt.WriteTimeout,
DialTimeout: opt.DialTimeout,
ReadTimeout: opt.ReadTimeout,
WriteTimeout: opt.WriteTimeout,
ContextTimeoutEnabled: opt.ContextTimeoutEnabled,
PoolFIFO: opt.PoolFIFO,
PoolSize: opt.PoolSize,
PoolTimeout: opt.PoolTimeout,
MinIdleConns: opt.MinIdleConns,
MaxIdleConns: opt.MaxIdleConns,
MaxActiveConns: opt.MaxActiveConns,
ConnMaxIdleTime: opt.ConnMaxIdleTime,
ConnMaxLifetime: opt.ConnMaxLifetime,
TLSConfig: opt.TLSConfig,
Limiter: opt.Limiter,
DisableIndentity: opt.DisableIndentity,
}
}
@ -670,21 +678,8 @@ func (c *Ring) cmdsInfo(ctx context.Context) (map[string]*CommandInfo, error) {
return nil, firstErr
}
func (c *Ring) cmdInfo(ctx context.Context, name string) *CommandInfo {
cmdsInfo, err := c.cmdsInfoCache.Get(ctx)
if err != nil {
return nil
}
info := cmdsInfo[name]
if info == nil {
internal.Logger.Printf(ctx, "info for cmd=%s not found", name)
}
return info
}
func (c *Ring) cmdShard(ctx context.Context, cmd Cmder) (*ringShard, error) {
cmdInfo := c.cmdInfo(ctx, cmd.Name())
pos := cmdFirstKeyPos(cmd, cmdInfo)
pos := cmdFirstKeyPos(cmd)
if pos == 0 {
return c.sharding.Random()
}
@ -752,8 +747,7 @@ func (c *Ring) generalProcessPipeline(
cmdsMap := make(map[string][]Cmder)
for _, cmd := range cmds {
cmdInfo := c.cmdInfo(ctx, cmd.Name())
hash := cmd.stringArg(cmdFirstKeyPos(cmd, cmdInfo))
hash := cmd.stringArg(cmdFirstKeyPos(cmd))
if hash != "" {
hash = c.sharding.Hash(hash)
}

View File

@ -74,10 +74,13 @@ type FailoverOptions struct {
PoolTimeout time.Duration
MinIdleConns int
MaxIdleConns int
MaxActiveConns int
ConnMaxIdleTime time.Duration
ConnMaxLifetime time.Duration
TLSConfig *tls.Config
DisableIndentity bool
}
func (opt *FailoverOptions) clientOptions() *Options {
@ -107,10 +110,13 @@ func (opt *FailoverOptions) clientOptions() *Options {
PoolTimeout: opt.PoolTimeout,
MinIdleConns: opt.MinIdleConns,
MaxIdleConns: opt.MaxIdleConns,
MaxActiveConns: opt.MaxActiveConns,
ConnMaxIdleTime: opt.ConnMaxIdleTime,
ConnMaxLifetime: opt.ConnMaxLifetime,
TLSConfig: opt.TLSConfig,
DisableIndentity: opt.DisableIndentity,
}
}
@ -130,15 +136,17 @@ func (opt *FailoverOptions) sentinelOptions(addr string) *Options {
MinRetryBackoff: opt.MinRetryBackoff,
MaxRetryBackoff: opt.MaxRetryBackoff,
DialTimeout: opt.DialTimeout,
ReadTimeout: opt.ReadTimeout,
WriteTimeout: opt.WriteTimeout,
DialTimeout: opt.DialTimeout,
ReadTimeout: opt.ReadTimeout,
WriteTimeout: opt.WriteTimeout,
ContextTimeoutEnabled: opt.ContextTimeoutEnabled,
PoolFIFO: opt.PoolFIFO,
PoolSize: opt.PoolSize,
PoolTimeout: opt.PoolTimeout,
MinIdleConns: opt.MinIdleConns,
MaxIdleConns: opt.MaxIdleConns,
MaxActiveConns: opt.MaxActiveConns,
ConnMaxIdleTime: opt.ConnMaxIdleTime,
ConnMaxLifetime: opt.ConnMaxLifetime,
@ -165,15 +173,17 @@ func (opt *FailoverOptions) clusterOptions() *ClusterOptions {
MinRetryBackoff: opt.MinRetryBackoff,
MaxRetryBackoff: opt.MaxRetryBackoff,
DialTimeout: opt.DialTimeout,
ReadTimeout: opt.ReadTimeout,
WriteTimeout: opt.WriteTimeout,
DialTimeout: opt.DialTimeout,
ReadTimeout: opt.ReadTimeout,
WriteTimeout: opt.WriteTimeout,
ContextTimeoutEnabled: opt.ContextTimeoutEnabled,
PoolFIFO: opt.PoolFIFO,
PoolSize: opt.PoolSize,
PoolTimeout: opt.PoolTimeout,
MinIdleConns: opt.MinIdleConns,
MaxIdleConns: opt.MaxIdleConns,
MaxActiveConns: opt.MaxActiveConns,
ConnMaxIdleTime: opt.ConnMaxIdleTime,
ConnMaxLifetime: opt.ConnMaxLifetime,

View File

@ -727,7 +727,7 @@ func (c cmdable) ZScan(ctx context.Context, key string, cursor uint64, match str
// Z represents sorted set member.
type Z struct {
Score float64
Member interface{}
Member string
}
// ZWithKey represents sorted set member including the name of the key where it was popped.

View File

@ -531,6 +531,8 @@ func (c cmdable) TSInfoWithArgs(ctx context.Context, key string, options *TSInfo
}
// TSMAdd - Adds multiple samples to multiple time-series keys.
// It accepts a slice of 'ktv' slices, each containing exactly three elements: key, timestamp, and value.
// This struct must be provided for this command to work.
// For more information - https://redis.io/commands/ts.madd/
func (c cmdable) TSMAdd(ctx context.Context, ktvSlices [][]interface{}) *IntSliceCmd {
args := []interface{}{"TS.MADD"}

View File

@ -15,7 +15,7 @@ var _ = Describe("RedisTimeseries commands", Label("timeseries"), func() {
var client *redis.Client
BeforeEach(func() {
client = redis.NewClient(&redis.Options{Addr: ":6379"})
client = redis.NewClient(&redis.Options{Addr: rediStackAddr})
Expect(client.FlushDB(ctx).Err()).NotTo(HaveOccurred())
})
@ -290,15 +290,17 @@ var _ = Describe("RedisTimeseries commands", Label("timeseries"), func() {
Expect(result.Value).To(BeEquivalentTo(151))
})
It("should TSGet Latest", Label("timeseries", "tsgetlatest"), func() {
It("should TSGet Latest", Label("timeseries", "tsgetlatest", "NonRedisEnterprise"), func() {
resultGet, err := client.TSCreate(ctx, "tsgl-1").Result()
Expect(err).NotTo(HaveOccurred())
Expect(resultGet).To(BeEquivalentTo("OK"))
resultGet, err = client.TSCreate(ctx, "tsgl-2").Result()
Expect(err).NotTo(HaveOccurred())
Expect(resultGet).To(BeEquivalentTo("OK"))
resultGet, err = client.TSCreateRule(ctx, "tsgl-1", "tsgl-2", redis.Sum, 10).Result()
Expect(err).NotTo(HaveOccurred())
Expect(resultGet).To(BeEquivalentTo("OK"))
_, err = client.TSAdd(ctx, "tsgl-1", 1, 1).Result()
Expect(err).NotTo(HaveOccurred())
@ -344,7 +346,7 @@ var _ = Describe("RedisTimeseries commands", Label("timeseries"), func() {
Expect(result).To(BeEquivalentTo([]int64{1, 2, 3}))
})
It("should TSMGet and TSMGetWithArgs", Label("timeseries", "tsmget", "tsmgetWithArgs"), func() {
It("should TSMGet and TSMGetWithArgs", Label("timeseries", "tsmget", "tsmgetWithArgs", "NonRedisEnterprise"), func() {
opt := &redis.TSOptions{Labels: map[string]string{"Test": "This"}}
resultCreate, err := client.TSCreateWithArgs(ctx, "a", opt).Result()
Expect(err).NotTo(HaveOccurred())
@ -429,7 +431,7 @@ var _ = Describe("RedisTimeseries commands", Label("timeseries"), func() {
Expect(resultRange[0]).To(BeEquivalentTo(redis.TSTimestampValue{Timestamp: 22, Value: 1}))
})
It("should TSRange, TSRangeWithArgs", Label("timeseries", "tsrange", "tsrangeWithArgs"), func() {
It("should TSRange, TSRangeWithArgs", Label("timeseries", "tsrange", "tsrangeWithArgs", "NonRedisEnterprise"), func() {
for i := 0; i < 100; i++ {
_, err := client.TSAdd(ctx, "a", i, float64(i%7)).Result()
Expect(err).NotTo(HaveOccurred())
@ -541,7 +543,7 @@ var _ = Describe("RedisTimeseries commands", Label("timeseries"), func() {
Expect(len(resultRange)).To(BeEquivalentTo(7))
})
It("should TSRevRange, TSRevRangeWithArgs", Label("timeseries", "tsrevrange", "tsrevrangeWithArgs"), func() {
It("should TSRevRange, TSRevRangeWithArgs", Label("timeseries", "tsrevrange", "tsrevrangeWithArgs", "NonRedisEnterprise"), func() {
for i := 0; i < 100; i++ {
_, err := client.TSAdd(ctx, "a", i, float64(i%7)).Result()
Expect(err).NotTo(HaveOccurred())
@ -755,7 +757,7 @@ var _ = Describe("RedisTimeseries commands", Label("timeseries"), func() {
Expect(result["a"][2]).To(BeEquivalentTo([]interface{}{[]interface{}{int64(0), 5.0}, []interface{}{int64(5), 6.0}}))
})
It("should TSMRangeWithArgs Latest", Label("timeseries", "tsmrangeWithArgs", "tsmrangelatest"), func() {
It("should TSMRangeWithArgs Latest", Label("timeseries", "tsmrangeWithArgs", "tsmrangelatest", "NonRedisEnterprise"), func() {
resultCreate, err := client.TSCreate(ctx, "a").Result()
Expect(err).NotTo(HaveOccurred())
Expect(resultCreate).To(BeEquivalentTo("OK"))
@ -888,7 +890,7 @@ var _ = Describe("RedisTimeseries commands", Label("timeseries"), func() {
Expect(result["a"][2]).To(BeEquivalentTo([]interface{}{[]interface{}{int64(1), 10.0}, []interface{}{int64(0), 1.0}}))
})
It("should TSMRevRangeWithArgs Latest", Label("timeseries", "tsmrevrangeWithArgs", "tsmrevrangelatest"), func() {
It("should TSMRevRangeWithArgs Latest", Label("timeseries", "tsmrevrangeWithArgs", "tsmrevrangelatest", "NonRedisEnterprise"), func() {
resultCreate, err := client.TSCreate(ctx, "a").Result()
Expect(err).NotTo(HaveOccurred())
Expect(resultCreate).To(BeEquivalentTo("OK"))

View File

@ -64,7 +64,7 @@ var _ = Describe("Tx", func() {
Expect(n).To(Equal(int64(100)))
})
It("should discard", func() {
It("should discard", Label("NonRedisEnterprise"), func() {
err := client.Watch(ctx, func(tx *redis.Tx) error {
cmds, err := tx.TxPipelined(ctx, func(pipe redis.Pipeliner) error {
pipe.Set(ctx, "key1", "hello1", 0)

View File

@ -48,6 +48,7 @@ type UniversalOptions struct {
PoolTimeout time.Duration
MinIdleConns int
MaxIdleConns int
MaxActiveConns int
ConnMaxIdleTime time.Duration
ConnMaxLifetime time.Duration
@ -64,6 +65,8 @@ type UniversalOptions struct {
// Only failover clients.
MasterName string
DisableIndentity bool
}
// Cluster returns cluster options created from the universal options.
@ -102,10 +105,13 @@ func (o *UniversalOptions) Cluster() *ClusterOptions {
PoolTimeout: o.PoolTimeout,
MinIdleConns: o.MinIdleConns,
MaxIdleConns: o.MaxIdleConns,
MaxActiveConns: o.MaxActiveConns,
ConnMaxIdleTime: o.ConnMaxIdleTime,
ConnMaxLifetime: o.ConnMaxLifetime,
TLSConfig: o.TLSConfig,
DisableIndentity: o.DisableIndentity,
}
}
@ -144,10 +150,13 @@ func (o *UniversalOptions) Failover() *FailoverOptions {
PoolTimeout: o.PoolTimeout,
MinIdleConns: o.MinIdleConns,
MaxIdleConns: o.MaxIdleConns,
MaxActiveConns: o.MaxActiveConns,
ConnMaxIdleTime: o.ConnMaxIdleTime,
ConnMaxLifetime: o.ConnMaxLifetime,
TLSConfig: o.TLSConfig,
DisableIndentity: o.DisableIndentity,
}
}
@ -183,10 +192,13 @@ func (o *UniversalOptions) Simple() *Options {
PoolTimeout: o.PoolTimeout,
MinIdleConns: o.MinIdleConns,
MaxIdleConns: o.MaxIdleConns,
MaxActiveConns: o.MaxActiveConns,
ConnMaxIdleTime: o.ConnMaxIdleTime,
ConnMaxLifetime: o.ConnMaxLifetime,
TLSConfig: o.TLSConfig,
DisableIndentity: o.DisableIndentity,
}
}

View File

@ -32,7 +32,7 @@ var _ = Describe("UniversalClient", func() {
Expect(client.Ping(ctx).Err()).NotTo(HaveOccurred())
})
It("should connect to clusters", func() {
It("should connect to clusters", Label("NonRedisEnterprise"), func() {
client = redis.NewUniversalClient(&redis.UniversalOptions{
Addrs: cluster.addrs(),
})

View File

@ -2,5 +2,5 @@ package redis
// Version is the current release version.
func Version() string {
return "9.2.1"
return "9.3.1"
}