Skip to content

Commit b1b84e7

Browse files
authored
Merge branch 'master' into add-conn-pool-wait-stats
2 parents ec26ba5 + b5a9e5d commit b1b84e7

File tree

29 files changed

+290
-53
lines changed

29 files changed

+290
-53
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ jobs:
2323
steps:
2424
- uses: actions/checkout@v4
2525
- name: golangci-lint
26-
uses: golangci/golangci-lint-action@v3
26+
uses: golangci/golangci-lint-action@v4

.github/workflows/release-drafter.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
runs-on: ubuntu-latest
1717
steps:
1818
# Drafts your next Release notes as Pull Requests are merged into "master"
19-
- uses: release-drafter/release-drafter@v5
19+
- uses: release-drafter/release-drafter@v6
2020
with:
2121
# (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml
2222
config-name: release-drafter-config.yml

.github/workflows/spellcheck.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
- name: Checkout
99
uses: actions/checkout@v4
1010
- name: Check Spelling
11-
uses: rojopolis/spellcheck-github-actions@0.35.0
11+
uses: rojopolis/spellcheck-github-actions@0.36.0
1212
with:
1313
config_path: .github/spellcheck-settings.yml
1414
task_name: Markdown

.github/workflows/test-redis-enterprise.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
fail-fast: false
1717
matrix:
1818
go-version: [1.21.x]
19-
re-build: ["7.2.4-92"]
19+
re-build: ["7.2.4-108"]
2020

2121
steps:
2222
- name: Checkout code

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ key value NoSQL database that uses RocksDB as storage engine and is compatible w
5151

5252
## Features
5353

54-
- Redis 3 commands except QUIT, MONITOR, and SYNC.
55-
- Automatic connection pooling with
54+
- Redis commands except QUIT and SYNC.
55+
- Automatic connection pooling.
5656
- [Pub/Sub](https://redis.uptrace.dev/guide/go-redis-pubsub.html).
5757
- [Pipelines and transactions](https://redis.uptrace.dev/guide/go-redis-pipelines.html).
5858
- [Scripting](https://redis.uptrace.dev/guide/lua-scripting.html).

bitmap_commands.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package redis
22

33
import (
44
"context"
5+
"errors"
56
)
67

78
type BitMapCmdable interface {
@@ -37,15 +38,28 @@ func (c cmdable) SetBit(ctx context.Context, key string, offset int64, value int
3738

3839
type BitCount struct {
3940
Start, End int64
41+
Unit string // BYTE(default) | BIT
4042
}
4143

44+
const BitCountIndexByte string = "BYTE"
45+
const BitCountIndexBit string = "BIT"
46+
4247
func (c cmdable) BitCount(ctx context.Context, key string, bitCount *BitCount) *IntCmd {
4348
args := []interface{}{"bitcount", key}
4449
if bitCount != nil {
50+
if bitCount.Unit == "" {
51+
bitCount.Unit = "BYTE"
52+
}
53+
if bitCount.Unit != BitCountIndexByte && bitCount.Unit != BitCountIndexBit {
54+
cmd := NewIntCmd(ctx)
55+
cmd.SetErr(errors.New("redis: invalid bitcount index"))
56+
return cmd
57+
}
4558
args = append(
4659
args,
4760
bitCount.Start,
4861
bitCount.End,
62+
string(bitCount.Unit),
4963
)
5064
}
5165
cmd := NewIntCmd(ctx, args...)

bitmap_commands_test.go

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package redis_test
2+
3+
import (
4+
. "github.com/bsm/ginkgo/v2"
5+
. "github.com/bsm/gomega"
6+
"github.com/redis/go-redis/v9"
7+
)
8+
9+
type bitCountExpected struct {
10+
Start int64
11+
End int64
12+
Expected int64
13+
}
14+
15+
var _ = Describe("BitCountBite", func() {
16+
var client *redis.Client
17+
key := "bit_count_test"
18+
19+
BeforeEach(func() {
20+
client = redis.NewClient(redisOptions())
21+
Expect(client.FlushDB(ctx).Err()).NotTo(HaveOccurred())
22+
values := []int{0, 1, 0, 0, 1, 0, 1, 0, 1, 1}
23+
for i, v := range values {
24+
cmd := client.SetBit(ctx, key, int64(i), v)
25+
Expect(cmd.Err()).NotTo(HaveOccurred())
26+
}
27+
})
28+
29+
AfterEach(func() {
30+
Expect(client.Close()).NotTo(HaveOccurred())
31+
})
32+
33+
It("bit count bite", func() {
34+
var expected = []bitCountExpected{
35+
{0, 0, 0},
36+
{0, 1, 1},
37+
{0, 2, 1},
38+
{0, 3, 1},
39+
{0, 4, 2},
40+
{0, 5, 2},
41+
{0, 6, 3},
42+
{0, 7, 3},
43+
{0, 8, 4},
44+
{0, 9, 5},
45+
}
46+
47+
for _, e := range expected {
48+
cmd := client.BitCount(ctx, key, &redis.BitCount{Start: e.Start, End: e.End, Unit: redis.BitCountIndexBit})
49+
Expect(cmd.Err()).NotTo(HaveOccurred())
50+
Expect(cmd.Val()).To(Equal(e.Expected))
51+
}
52+
})
53+
})
54+
55+
var _ = Describe("BitCountByte", func() {
56+
var client *redis.Client
57+
key := "bit_count_test"
58+
59+
BeforeEach(func() {
60+
client = redis.NewClient(redisOptions())
61+
Expect(client.FlushDB(ctx).Err()).NotTo(HaveOccurred())
62+
values := []int{0, 0, 0, 0, 0, 0, 0, 1, 1, 1}
63+
for i, v := range values {
64+
cmd := client.SetBit(ctx, key, int64(i), v)
65+
Expect(cmd.Err()).NotTo(HaveOccurred())
66+
}
67+
})
68+
69+
AfterEach(func() {
70+
Expect(client.Close()).NotTo(HaveOccurred())
71+
})
72+
73+
It("bit count byte", func() {
74+
var expected = []bitCountExpected{
75+
{0, 0, 1},
76+
{0, 1, 3},
77+
}
78+
79+
for _, e := range expected {
80+
cmd := client.BitCount(ctx, key, &redis.BitCount{Start: e.Start, End: e.End, Unit: redis.BitCountIndexByte})
81+
Expect(cmd.Err()).NotTo(HaveOccurred())
82+
Expect(cmd.Val()).To(Equal(e.Expected))
83+
}
84+
})
85+
86+
It("bit count byte with no unit specified", func() {
87+
var expected = []bitCountExpected{
88+
{0, 0, 1},
89+
{0, 1, 3},
90+
}
91+
92+
for _, e := range expected {
93+
cmd := client.BitCount(ctx, key, &redis.BitCount{Start: e.Start, End: e.End})
94+
Expect(cmd.Err()).NotTo(HaveOccurred())
95+
Expect(cmd.Val()).To(Equal(e.Expected))
96+
}
97+
})
98+
})

command.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5310,6 +5310,16 @@ type LibraryInfo struct {
53105310
LibVer *string
53115311
}
53125312

5313+
// WithLibraryName returns a valid LibraryInfo with library name only.
5314+
func WithLibraryName(libName string) LibraryInfo {
5315+
return LibraryInfo{LibName: &libName}
5316+
}
5317+
5318+
// WithLibraryVersion returns a valid LibraryInfo with library version only.
5319+
func WithLibraryVersion(libVer string) LibraryInfo {
5320+
return LibraryInfo{LibVer: &libVer}
5321+
}
5322+
53135323
// -------------------------------------------
53145324

53155325
type InfoCmd struct {

commands_test.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ var _ = Describe("Commands", func() {
248248

249249
// Test setting the libName
250250
libName := "go-redis"
251-
libInfo := redis.LibraryInfo{LibName: &libName}
251+
libInfo := redis.WithLibraryName(libName)
252252
setInfo := pipe.ClientSetInfo(ctx, libInfo)
253253
_, err := pipe.Exec(ctx)
254254

@@ -258,7 +258,7 @@ var _ = Describe("Commands", func() {
258258

259259
// Test setting the libVer
260260
libVer := "vX.x"
261-
libInfo = redis.LibraryInfo{LibVer: &libVer}
261+
libInfo = redis.WithLibraryVersion(libVer)
262262
setInfo = pipe.ClientSetInfo(ctx, libInfo)
263263
_, err = pipe.Exec(ctx)
264264

@@ -676,7 +676,7 @@ var _ = Describe("Commands", func() {
676676
Expect(get.Val()).To(Equal("hello"))
677677
})
678678

679-
It("should Object", func() {
679+
It("should Object", Label("NonRedisEnterprise"), func() {
680680
start := time.Now()
681681
set := client.Set(ctx, "key", "hello", 0)
682682
Expect(set.Err()).NotTo(HaveOccurred())
@@ -686,6 +686,11 @@ var _ = Describe("Commands", func() {
686686
Expect(refCount.Err()).NotTo(HaveOccurred())
687687
Expect(refCount.Val()).To(Equal(int64(1)))
688688

689+
client.ConfigSet(ctx, "maxmemory-policy", "volatile-lfu")
690+
freq := client.ObjectFreq(ctx, "key")
691+
Expect(freq.Err()).NotTo(HaveOccurred())
692+
client.ConfigSet(ctx, "maxmemory-policy", "noeviction") // default
693+
689694
err := client.ObjectEncoding(ctx, "key").Err()
690695
Expect(err).NotTo(HaveOccurred())
691696

@@ -2100,7 +2105,7 @@ var _ = Describe("Commands", func() {
21002105

21012106
logEntries, err := client.ACLLog(ctx, 10).Result()
21022107
Expect(err).NotTo(HaveOccurred())
2103-
Expect(len(logEntries)).To(Equal(4))
2108+
Expect(len(logEntries)).To(Equal(1))
21042109

21052110
for _, entry := range logEntries {
21062111
Expect(entry.Reason).To(Equal("command"))
@@ -2116,7 +2121,7 @@ var _ = Describe("Commands", func() {
21162121

21172122
limitedLogEntries, err := client.ACLLog(ctx, 2).Result()
21182123
Expect(err).NotTo(HaveOccurred())
2119-
Expect(len(limitedLogEntries)).To(Equal(2))
2124+
Expect(len(limitedLogEntries)).To(Equal(1))
21202125
})
21212126

21222127
It("should ACL LOG RESET", Label("NonRedisEnterprise"), func() {

example/del-keys-without-ttl/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.18
55
replace github.com/redis/go-redis/v9 => ../..
66

77
require (
8-
github.com/redis/go-redis/v9 v9.4.0
8+
github.com/redis/go-redis/v9 v9.5.0
99
go.uber.org/zap v1.24.0
1010
)
1111

0 commit comments

Comments
 (0)