8000 fix: lorry support redis 5.x by kizuna-lek · Pull Request #8746 · apecloud/kubeblocks · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: lorry support redis 5.x #8746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10000
40 changes: 38 additions & 2 deletions pkg/lorry/engines/redis/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ package redis
import (
"context"
"fmt"
"os/exec"
"strconv"
"strings"
"time"

Expand All @@ -44,7 +46,6 @@ type Manager struct {
clientSettings *Settings
sentinelClient *redis.SentinelClient

startAt time.Time
role string
roleSubscribeUpdateTime int64
roleProbePeriod int64
Expand Down Expand Up @@ -76,7 +77,14 @@ func NewManager(properties engines.Properties) (engines.DBManager, error) {
roleProbePeriod: int64(viper.GetInt(constant.KBEnvRoleProbePeriod)),
}

mgr.startAt = time.Now()
majorVersion, err := getRedisMajorVersion()
if err != nil {
return nil, err
}
// The username is supported after 6.0
if majorVersion < 6 {
redisUser = ""
}

defaultSettings := &Settings{
Password: redisPasswd,
Expand Down Expand Up @@ -120,3 +128,31 @@ func tokenizeCmd2Args(cmd string) []interface{} {
}
return redisArgs
}

// we get redis version from 'redis-cli --version'
func getRedisMajorVersion() (int, error) {
redisCliCMD, err := exec.LookPath("redis-cli")
if err != nil {
if viper.IsSet("REDIS_VERSION") {
return strconv.Atoi(strings.Split(strings.TrimSpace(viper.GetString("REDIS_VERSION")), ".")[0])
}
return -1, err
}

out, err := exec.Command(redisCliCMD, "--version").Output()
if err != nil {
return -1, err
}

// output eg: redis-cli 7.2.4
versionInfo := strings.Split(strings.TrimSpace(string(out)), " ")
if len(versionInfo) < 2 {
return -1, fmt.Errorf("invalid redis version info: %s", string(out))
}

majorVersion, err := strconv.Atoi(strings.Split(strings.TrimSpace(versionInfo[1]), ".")[0])
if err != nil {
return -1, err
}
return majorVersion, nil
}
1 change: 1 addition & 0 deletions pkg/lorry/engines/redis/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var _ = Describe("Redis DBManager", func() {
// Set up relevant viper config variables
viper.Set(constant.KBEnvServiceUser, "testuser")
viper.Set(constant.KBEnvServicePassword, "testpassword")
viper.Set("REDIS_VERSION", "7.2.4")
Context("new db manager", func() {
It("with right configurations", func() {
properties := engines.Properties{
Expand Down
Loading
0