Skip to content

Commit ae6dfd2

Browse files
authored
Merge branch 'master' into connection_issue
2 parents 323f8ef + d8a9655 commit ae6dfd2

27 files changed

+1139
-165
lines changed

.github/actions/run-tests/action.yml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: 'Run go-redis tests'
2+
description: 'Runs go-redis tests against different Redis versions and configurations'
3+
inputs:
4+
go-version:
5+
description: 'Go version to use for running tests'
6+
default: '1.23'
7+
redis-version:
8+
description: 'Redis version to test against'
9+
required: true
10+
runs:
11+
using: "composite"
12+
steps:
13+
- name: Set up ${{ inputs.go-version }}
14+
uses: actions/setup-go@v5
15+
with:
16+
go-version: ${{ inputs.go-version }}
17+
18+
- name: Setup Test environment
19+
env:
20+
REDIS_VERSION: ${{ inputs.redis-version }}
21+
CLIENT_LIBS_TEST_IMAGE: "redislabs/client-libs-test:${{ inputs.redis-version }}"
22+
run: |
23+
set -e
24+
redis_major_version=$(echo "$REDIS_VERSION" | grep -oP '^\d+')
25+
if (( redis_major_version < 8 )); then
26+
echo "Using redis-stack for module tests"
27+
else
28+
echo "Using redis CE for module tests"
29+
fi
30+
31+
# Mapping of redis version to redis testing containers
32+
declare -A redis_version_mapping=(
33+
["8.0-M03"]="8.0-M04-pre"
34+
["7.4.2"]="rs-7.4.0-v2"
35+
["7.2.7"]="rs-7.2.0-v14"
36+
)
37+
38+
if [[ -v redis_version_mapping[$REDIS_VERSION] ]]; then
39+
echo "REDIS_MAJOR_VERSION=${redis_major_version}" >> $GITHUB_ENV
40+
echo "REDIS_IMAGE=redis:${{ inputs.redis-version }}" >> $GITHUB_ENV
41+
echo "CLIENT_LIBS_TEST_IMAGE=redislabs/client-libs-test:${redis_version_mapping[$REDIS_VERSION]}" >> $GITHUB_ENV
42+
else
43+
echo "Version not found in the mapping."
44+
exit 1
45+
fi
46+
sleep 10 # time to settle
47+
shell: bash
48+
- name: Set up Docker Compose environment with redis ${{ inputs.redis-version }}
49+
run: docker compose --profile all up -d
50+
shell: bash
51+
- name: Run tests
52+
env:
53+
RCE_DOCKER: "true"
54+
RE_CLUSTER: "false"
55+
run: |
56+
go test \
57+
--ginkgo.skip-file="ring_test.go" \
58+
--ginkgo.skip-file="sentinel_test.go" \
59+
--ginkgo.skip-file="pubsub_test.go" \
60+
--ginkgo.skip-file="gears_commands_test.go" \
61+
--ginkgo.label-filter="!NonRedisEnterprise"
62+
shell: bash

.github/workflows/build.yml

+28-10
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,7 @@ jobs:
1616
strategy:
1717
fail-fast: false
1818
matrix:
19-
go-version: [1.19.x, 1.20.x, 1.21.x]
20-
21-
services:
22-
redis:
23-
image: redis/redis-stack-server:latest
24-
options: >-
25-
--health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5
26-
ports:
27-
- 6379:6379
19+
go-version: [1.21.x, 1.22.x, 1.23.x]
2820

2921
steps:
3022
- name: Set up ${{ matrix.go-version }}
@@ -42,4 +34,30 @@ jobs:
4234
uses: codecov/codecov-action@v5
4335
with:
4436
files: coverage.txt
45-
token: ${{ secrets.CODECOV_TOKEN }}
37+
token: ${{ secrets.CODECOV_TOKEN }}
38+
39+
test-redis-ce:
40+
name: test-redis-ce
41+
runs-on: ubuntu-latest
42+
strategy:
43+
fail-fast: false
44+
matrix:
45+
redis-version:
46+
- "8.0-M03" # 8.0 milestone 4
47+
- "7.4.2" # should use redis stack 7.4
48+
- "7.2.7" # should redis stack 7.2
49+
go-version:
50+
- "1.22.x"
51+
- "1.23.x"
52+
53+
steps:
54+
55+
- name: Checkout code
56+
uses: actions/checkout@v4
57+
58+
- name: Run tests
59+
uses: ./.github/actions/run-tests
60+
with:
61+
go-version: ${{matrix.go-version}}
62+
redis-version: ${{ matrix.redis-version }}
63+

.github/workflows/doctests.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
strategy:
2626
fail-fast: false
2727
matrix:
28-
go-version: [ "1.18", "1.19", "1.20", "1.21" ]
28+
go-version: [ "1.21", "1.22", "1.23" ]
2929

3030
steps:
3131
- name: Set up ${{ matrix.go-version }}

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
strategy:
1616
fail-fast: false
1717
matrix:
18-
go-version: [1.21.x]
18+
go-version: [1.23.x]
1919
re-build: ["7.4.2-54"]
2020

2121
steps:
@@ -46,7 +46,8 @@ jobs:
4646

4747
- name: Test
4848
env:
49-
RE_CLUSTER: "1"
49+
RE_CLUSTER: true
50+
REDIS_MAJOR_VERSION: 7
5051
run: |
5152
go test \
5253
--ginkgo.skip-file="ring_test.go" \

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ testdata/*
33
.idea/
44
.DS_Store
55
*.tar.gz
6-
*.dic
6+
*.dic
7+
redis8tests.sh

Makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
GO_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {} \; | sort)
2+
export REDIS_MAJOR_VERSION := 7
23

34
test: testdeps
5+
docker start go-redis-redis-stack || docker run -d --name go-redis-redis-stack -p 6379:6379 -e REDIS_ARGS="--enable-debug-command yes --enable-module-command yes" redis/redis-stack-server:latest
46
$(eval GO_VERSION := $(shell go version | cut -d " " -f 3 | cut -d. -f2))
57
set -e; for dir in $(GO_MOD_DIRS); do \
68
if echo "$${dir}" | grep -q "./example" && [ "$(GO_VERSION)" = "19" ]; then \
@@ -19,6 +21,7 @@ test: testdeps
1921
done
2022
cd internal/customvet && go build .
2123
go vet -vettool ./internal/customvet/customvet
24+
docker stop go-redis-redis-stack
2225

2326
testdeps: testdata/redis/src/redis-server
2427

@@ -32,7 +35,7 @@ build:
3235

3336
testdata/redis:
3437
mkdir -p $@
35-
wget -qO- https://download.redis.io/releases/redis-7.4-rc2.tar.gz | tar xvz --strip-components=1 -C $@
38+
wget -qO- https://download.redis.io/releases/redis-7.4.2.tar.gz | tar xvz --strip-components=1 -C $@
3639

3740
testdata/redis/src/redis-server: testdata/redis
3841
cd $< && make all

bench_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ func BenchmarkXRead(b *testing.B) {
277277

278278
func newClusterScenario() *clusterScenario {
279279
return &clusterScenario{
280-
ports: []string{"8220", "8221", "8222", "8223", "8224", "8225"},
280+
ports: []string{"16600", "16601", "16602", "16603", "16604", "16605"},
281281
nodeIDs: make([]string, 6),
282282
processes: make(map[string]*redisProcess, 6),
283283
clients: make(map[string]*redis.Client, 6),

command.go

+36-15
Original file line numberDiff line numberDiff line change
@@ -3862,30 +3862,48 @@ func (cmd *MapMapStringInterfaceCmd) Val() map[string]interface{} {
38623862
return cmd.val
38633863
}
38643864

3865+
// readReply will try to parse the reply from the proto.Reader for both resp2 and resp3
38653866
func (cmd *MapMapStringInterfaceCmd) readReply(rd *proto.Reader) (err error) {
3866-
n, err := rd.ReadArrayLen()
3867+
data, err := rd.ReadReply()
38673868
if err != nil {
38683869
return err
38693870
}
3871+
resultMap := map[string]interface{}{}
38703872

3871-
data := make(map[string]interface{}, n/2)
3872-
for i := 0; i < n; i += 2 {
3873-
_, err := rd.ReadArrayLen()
3874-
if err != nil {
3875-
cmd.err = err
3876-
}
3877-
key, err := rd.ReadString()
3878-
if err != nil {
3879-
cmd.err = err
3873+
switch midResponse := data.(type) {
3874+
case map[interface{}]interface{}: // resp3 will return map
3875+
for k, v := range midResponse {
3876+
stringKey, ok := k.(string)
3877+
if !ok {
3878+
return fmt.Errorf("redis: invalid map key %#v", k)
3879+
}
3880+
resultMap[stringKey] = v
38803881
}
3881-
value, err := rd.ReadString()
3882-
if err != nil {
3883-
cmd.err = err
3882+
case []interface{}: // resp2 will return array of arrays
3883+
n := len(midResponse)
3884+
for i := 0; i < n; i++ {
3885+
finalArr, ok := midResponse[i].([]interface{}) // final array that we need to transform to map
3886+
if !ok {
3887+
return fmt.Errorf("redis: unexpected response %#v", data)
3888+
}
3889+
m := len(finalArr)
3890+
if m%2 != 0 { // since this should be map, keys should be even number
3891+
return fmt.Errorf("redis: unexpected response %#v", data)
3892+
}
3893+
3894+
for j := 0; j < m; j += 2 {
3895+
stringKey, ok := finalArr[j].(string) // the first one
3896+
if !ok {
3897+
return fmt.Errorf("redis: invalid map key %#v", finalArr[i])
3898+
}
3899+
resultMap[stringKey] = finalArr[j+1] // second one is value
3900+
}
38843901
}
3885-
data[key] = value
3902+
default:
3903+
return fmt.Errorf("redis: unexpected response %#v", data)
38863904
}
38873905

3888-
cmd.val = data
3906+
cmd.val = resultMap
38893907
return nil
38903908
}
38913909

@@ -5114,6 +5132,7 @@ type ClientInfo struct {
51145132
OutputListLength int // oll, output list length (replies are queued in this list when the buffer is full)
51155133
OutputMemory int // omem, output buffer memory usage
51165134
TotalMemory int // tot-mem, total memory consumed by this client in its various buffers
5135+
IoThread int // io-thread id
51175136
Events string // file descriptor events (see below)
51185137
LastCmd string // cmd, last command played
51195138
User string // the authenticated username of the client
@@ -5292,6 +5311,8 @@ func parseClientInfo(txt string) (info *ClientInfo, err error) {
52925311
info.LibName = val
52935312
case "lib-ver":
52945313
info.LibVer = val
5314+
case "io-thread":
5315+
info.IoThread, err = strconv.Atoi(val)
52955316
default:
52965317
return nil, fmt.Errorf("redis: unexpected client info key(%s)", key)
52975318
}

0 commit comments

Comments
 (0)