diff --git a/README.md b/README.md
index 7ae280e..296b2d1 100644
--- a/README.md
+++ b/README.md
@@ -19,7 +19,7 @@ The type can be one of the followings:
* **restore**: Restore RDB file to target redis.
* **dump**: Dump RDB file from souce redis.
* **sync**: Sync data from source redis to target redis by `sync` or `psync` command. Including full synchronization and incremental synchronization.
-* **rump**: Sync data from source redis to target redis by `scan` command. Only support full synchronization. Plus, RedisShake also supports fetching data from given keys in the input file when `scan` command is not supported on the source side.
+* **rump**: Sync data from source redis to target redis by `scan` command. Only support full synchronization. Plus, RedisShake also supports fetching data from given keys in the input file when `scan` command is not supported on the source side. This mode is usually used when `sync` and `psync` redis commands aren't supported.
Please check out the `conf/redis-shake.conf` to see the detailed parameters description.
@@ -41,7 +41,7 @@ Redis-shake offers metrics through restful api and log file.
* restful api: `curl 127.0.0.1:9320/metric`.
* log: the metric info will be printed in the log periodically if enable.
-m
+* inner routine heap: `curl http://127.0.0.1:9310/debug/pprof/goroutine?debug=2`
# Redis Type
---
@@ -80,7 +80,7 @@ You can also build redis-shake yourself according to the following steps, the `g
* cd src/vendor
* govendor sync #please note: must install govendor first and then pull all dependencies: `go get -u github.com/kardianos/govendor`
* cd ../../ && ./build.sh
-* ./bin/redis-shake -type=$(type_must_be_sync_dump_restore_or_decode) -conf=conf/redis-shake.conf #please note: user must modify collector.conf first to match needs.
+* ./bin/redis-shake -type=$(type_must_be_sync_dump_restore_decode_or_rump) -conf=conf/redis-shake.conf #please note: user must modify collector.conf first to match needs.
# Shake series tool
---
@@ -90,7 +90,7 @@ We also provide some tools for synchronization in Shake series.
* [RedisShake](https://github.com/aliyun/RedisShake): redis data synchronization tool.
* [RedisFullCheck](https://github.com/aliyun/RedisFullCheck): redis data synchronization verification tool.
-Plus, we have a WeChat group so that users can join and discuss, but the group user number is limited. So please add my WeChat number: `vinllen_xingge` first, and I will add you to this group.
+Plus, we have a WeChat group so that users can join and discuss, but the group user number is limited. So please add my WeChat number: `vinllen_xingge` first, and I will add you to this group. (<-微信加群请戳这)
# Thanks
---
diff --git a/src/redis-shake/common/command.go b/src/redis-shake/common/command.go
index 1b81351..d7b7ab1 100644
--- a/src/redis-shake/common/command.go
+++ b/src/redis-shake/common/command.go
@@ -7,6 +7,7 @@ import (
"redis-shake/configure"
redigo "github.com/garyburd/redigo/redis"
+ "strings"
)
type ClusterNodeInfo struct {
@@ -21,6 +22,47 @@ type ClusterNodeInfo struct {
Slot string
}
+// parse single info field: "info server", "info keyspace"
+func ParseRedisInfo(content []byte) map[string]string {
+ result := make(map[string]string, 10)
+ lines := bytes.Split(content, []byte("\r\n"))
+ for i := 0; i < len(lines); i++ {
+ items := bytes.SplitN(lines[i], []byte(":"), 2)
+ if len(items) != 2 {
+ continue
+ }
+ result[string(items[0])] = string(items[1])
+ }
+ return result
+}
+
+// cut segment
+func CutRedisInfoSegment(content []byte, field string) []byte {
+ field1 := strings.ToLower(field)
+ field2 := "# " + field1
+ segmentSplitter := []byte{13, 10, 35, 32} // \r\n#
+ lineSplitter := []byte{13, 10}
+ segments := bytes.Split(content, segmentSplitter)
+ for i, segment := range segments {
+ lines := bytes.Split(segment, lineSplitter)
+ if len(lines) == 0 {
+ continue
+ }
+
+ cmd := strings.ToLower(string(lines[0]))
+ if cmd == field1 || cmd == field2 {
+ // match
+ var newSeg []byte
+ if i != 0 {
+ newSeg = []byte{35, 32}
+ }
+ newSeg = append(newSeg, segment...)
+ return newSeg
+ }
+ }
+ return nil
+}
+
func ParseKeyspace(content []byte) (map[int32]int64, error) {
if bytes.HasPrefix(content, []byte("# Keyspace")) == false {
return nil, fmt.Errorf("invalid info Keyspace: %s", string(content))
diff --git a/src/redis-shake/common/common.go b/src/redis-shake/common/common.go
index be093b0..c206e56 100644
--- a/src/redis-shake/common/common.go
+++ b/src/redis-shake/common/common.go
@@ -32,6 +32,8 @@ const (
TencentCluster = "tencent_cluster"
AliyunCluster = "aliyun_cluster"
UCloudCluster = "ucloud_cluster"
+
+ CoidsErrMsg = "ERR backend server 'server' not found"
)
var (
diff --git a/src/redis-shake/common/utils.go b/src/redis-shake/common/utils.go
index b1e0deb..9913998 100644
--- a/src/redis-shake/common/utils.go
+++ b/src/redis-shake/common/utils.go
@@ -864,27 +864,21 @@ func NewRDBLoader(reader *bufio.Reader, rbytes *atomic2.Int64, size int) chan *r
return pipe
}
-func ParseRedisInfo(content []byte) map[string]string {
- result := make(map[string]string, 10)
- lines := bytes.Split(content, []byte("\r\n"))
- for i := 0; i < len(lines); i++ {
- items := bytes.SplitN(lines[i], []byte(":"), 2)
- if len(items) != 2 {
- continue
- }
- result[string(items[0])] = string(items[1])
- }
- return result
-}
-
func GetRedisVersion(target, authType, auth string, tlsEnable bool) (string, error) {
c := OpenRedisConn([]string{target}, authType, auth, false, tlsEnable)
defer c.Close()
infoStr, err := redigo.Bytes(c.Do("info", "server"))
if err != nil {
- return "", err
+ if err.Error() == CoidsErrMsg {
+ // "info xxx" command is disable in codis, try to use "info" and parse "xxx"
+ infoStr, err = redigo.Bytes(c.Do("info"))
+ infoStr = CutRedisInfoSegment(infoStr, "server")
+ } else {
+ return "", err
+ }
}
+
infoKV := ParseRedisInfo(infoStr)
if value, ok := infoKV["redis_version"]; ok {
return value, nil
diff --git a/src/redis-shake/common/utils_test.go b/src/redis-shake/common/utils_test.go
index 88986e5..88a90ea 100644
--- a/src/redis-shake/common/utils_test.go
+++ b/src/redis-shake/common/utils_test.go
@@ -56,34 +56,30 @@ func TestGetAllClusterNode(t *testing.T) {
}
}
-func TestHasAtLeastOnePrefix(t *testing.T) {
- cases := []struct {
- key string
- prefixes []string
- expectResult bool
- }{
- {
- // no prefix provided
- "a",
- []string{},
- false,
- },
- {
- // has prefix
- "abc",
- []string{"ab"},
- true,
- },
- {
- // does NOT have prefix
- "abc",
- []string{"edf", "wab"},
- false,
- },
+func TestCutRedisInfoSegment(t *testing.T) {
+ input := []byte{35, 32, 83, 101, 114, 118, 101, 114, 13, 10, 114, 101, 100, 105, 115, 95, 118, 101, 114, 115, 105, 111, 110, 58, 51, 46, 50, 46, 49, 49, 13, 10, 114, 101, 100, 105, 115, 95, 103, 105, 116, 95, 115, 104, 97, 49, 58, 100, 101, 49, 97, 100, 48, 50, 54, 13, 10, 114, 101, 100, 105, 115, 95, 103, 105, 116, 95, 100, 105, 114, 116, 121, 58, 48, 13, 10, 114, 101, 100, 105, 115, 95, 98, 117, 105, 108, 100, 95, 105, 100, 58, 54, 101, 49, 99, 101, 51, 55, 97, 102, 101, 48, 54, 99, 51, 52, 99, 13, 10, 114, 101, 100, 105, 115, 95, 109, 111, 100, 101, 58, 115, 116, 97, 110, 100, 97, 108, 111, 110, 101, 13, 10, 111, 115, 58, 76, 105, 110, 117, 120, 32, 51, 46, 49, 48, 46, 48, 45, 57, 53, 55, 46, 50, 49, 46, 51, 46, 101, 108, 55, 46, 120, 56, 54, 95, 54, 52, 32, 120, 56, 54, 95, 54, 52, 13, 10, 97, 114, 99, 104, 95, 98, 105, 116, 115, 58, 54, 52, 13, 10, 109, 117, 108, 116, 105, 112, 108, 101, 120, 105, 110, 103, 95, 97, 112, 105, 58, 101, 112, 111, 108, 108, 13, 10, 103, 99, 99, 95, 118, 101, 114, 115, 105, 111, 110, 58, 52, 46, 56, 46, 53, 13, 10, 112, 114, 111, 99, 101, 115, 115, 95, 105, 100, 58, 57, 48, 54, 57, 13, 10, 114, 117, 110, 95, 105, 100, 58, 49, 52, 49, 98, 51, 54, 101, 102, 50, 51, 50, 57, 56, 52, 53, 54, 98, 52, 100, 97, 101, 48, 49, 51, 49, 50, 57, 49, 98, 50, 100, 101, 99, 99, 101, 102, 102, 52, 54, 53, 13, 10, 116, 99, 112, 95, 112, 111, 114, 116, 58, 56, 53, 48, 51, 13, 10, 117, 112, 116, 105, 109, 101, 95, 105, 110, 95, 115, 101, 99, 111, 110, 100, 115, 58, 53, 56, 57, 54, 51, 49, 13, 10, 117, 112, 116, 105, 109, 101, 95, 105, 110, 95, 100, 97, 121, 115, 58, 54, 13, 10, 104, 122, 58, 49, 48, 13, 10, 108, 114, 117, 95, 99, 108, 111, 99, 107, 58, 51, 55, 52, 50, 48, 50, 48, 13, 10, 101, 120, 101, 99, 117, 116, 97, 98, 108, 101, 58, 47, 100, 97, 116, 97, 47, 109, 97, 112, 103, 111, 111, 47, 99, 111, 100, 105, 115, 47, 46, 47, 98, 105, 110, 47, 99, 111, 100, 105, 115, 45, 115, 101, 114, 118, 101, 114, 13, 10, 99, 111, 110, 102, 105, 103, 95, 102, 105, 108, 101, 58, 47, 100, 97, 116, 97, 47, 109, 97, 112, 103, 111, 111, 47, 99, 111, 100, 105, 115, 47, 46, 47, 99, 111, 100, 105, 115, 95, 115, 101, 114, 118, 101, 114, 47, 99, 111, 110, 102, 47, 114, 101, 100, 105, 115, 45, 56, 53, 48, 51, 46, 99, 111, 110, 102, 13, 10, 13, 10, 35, 32, 67, 108, 105, 101, 110, 116, 115, 13, 10, 99, 111, 110, 110, 101, 99, 116, 101, 100, 95, 99, 108, 105, 101, 110, 116, 115, 58, 52, 57, 13, 10, 99, 108, 105, 101, 110, 116, 95, 108, 111, 110, 103, 101, 115, 116, 95, 111, 117, 116, 112, 117, 116, 95, 108, 105, 115, 116, 58, 48, 13, 10, 99, 108, 105, 101, 110, 116, 95, 98, 105, 103, 103, 101, 115, 116, 95, 105, 110, 112, 117, 116, 95, 98, 117, 102, 58, 48, 13, 10, 98, 108, 111, 99, 107, 101, 100, 95, 99, 108, 105, 101, 110, 116, 115, 58, 48, 13, 10, 13, 10, 35, 32, 77, 101, 109, 111, 114, 121, 13, 10, 117, 115, 101, 100, 95, 109, 101, 109, 111, 114, 121, 58, 51, 55, 51, 55, 49, 53, 50, 13, 10, 117, 115, 101, 100, 95, 109, 101, 109, 111, 114, 121, 95, 104, 117, 109, 97, 110, 58, 51, 46, 53, 54, 77, 13, 10, 117, 115, 101, 100, 95, 109, 101, 109, 111, 114, 121, 95, 114, 115, 115, 58, 52, 57, 51, 57, 55, 55, 54, 13, 10, 117, 115, 101, 100, 95, 109, 101, 109, 111, 114, 121, 95, 114, 115, 115, 95, 104, 117, 109, 97, 110, 58, 52, 46, 55, 49, 77, 13, 10, 117, 115, 101, 100, 95, 109, 101, 109, 111, 114, 121, 95, 112, 101, 97, 107, 58, 53, 51, 55, 52, 52, 48, 48, 13, 10, 117, 115, 101, 100, 95, 109, 101, 109, 111, 114, 121, 95, 112, 101, 97, 107, 95, 104, 117, 109, 97, 110, 58, 53, 46, 49, 51, 77, 13, 10, 116, 111, 116, 97, 108, 95, 115, 121, 115, 116, 101, 109, 95, 109, 101, 109, 111, 114, 121, 58, 54, 55, 51, 56, 55, 50, 56, 53, 53, 48, 52, 13, 10, 116, 111, 116, 97, 108, 95, 115, 121, 115, 116, 101, 109, 95, 109, 101, 109, 111, 114, 121, 95, 104, 117, 109, 97, 110, 58, 54, 50, 46, 55, 54, 71, 13, 10, 117, 115, 101, 100, 95, 109, 101, 109, 111, 114, 121, 95, 108, 117, 97, 58, 51, 55, 56, 56, 56, 13, 10, 117, 115, 101, 100, 95, 109, 101, 109, 111, 114, 121, 95, 108, 117, 97, 95, 104, 117, 109, 97, 110, 58, 51, 55, 46, 48, 48, 75, 13, 10, 109, 97, 120, 109, 101, 109, 111, 114, 121, 58, 48, 13, 10, 109, 97, 120, 109, 101, 109, 111, 114, 121, 95, 104, 117, 109, 97, 110, 58, 48, 66, 13, 10, 109, 97, 120, 109, 101, 109, 111, 114, 121, 95, 112, 111, 108, 105, 99, 121, 58, 110, 111, 101, 118, 105, 99, 116, 105, 111, 110, 13, 10, 109, 101, 109, 95, 102, 114, 97, 103, 109, 101, 110, 116, 97, 116, 105, 111, 110, 95, 114, 97, 116, 105, 111, 58, 49, 46, 51, 50, 13, 10, 109, 101, 109, 95, 97, 108, 108, 111, 99, 97, 116, 111, 114, 58, 106, 101, 109, 97, 108, 108, 111, 99, 45, 52, 46, 48, 46, 51, 13, 10, 13, 10, 35, 32, 80, 101, 114, 115, 105, 115, 116, 101, 110, 99, 101, 13, 10, 108, 111, 97, 100, 105, 110, 103, 58, 48, 13, 10, 114, 100, 98, 95, 99, 104, 97, 110, 103, 101, 115, 95, 115, 105, 110, 99, 101, 95, 108, 97, 115, 116, 95, 115, 97, 118, 101, 58, 48, 13, 10, 114, 100, 98, 95, 98, 103, 115, 97, 118, 101, 95, 105, 110, 95, 112, 114, 111, 103, 114, 101, 115, 115, 58, 48, 13, 10, 114, 100, 98, 95, 108, 97, 115, 116, 95, 115, 97, 118, 101, 95, 116, 105, 109, 101, 58, 49, 53, 54, 52, 48, 50, 49, 52, 57, 54, 13, 10, 114, 100, 98, 95, 108, 97, 115, 116, 95, 98, 103, 115, 97, 118, 101, 95, 115, 116, 97, 116, 117, 115, 58, 111, 107, 13, 10, 114, 100, 98, 95, 108, 97, 115, 116, 95, 98, 103, 115, 97, 118, 101, 95, 116, 105, 109, 101, 95, 115, 101, 99, 58, 48, 13, 10, 114, 100, 98, 95, 99, 117, 114, 114, 101, 110, 116, 95, 98, 103, 115, 97, 118, 101, 95, 116, 105, 109, 101, 95, 115, 101, 99, 58, 45, 49, 13, 10, 97, 111, 102, 95, 101, 110, 97, 98, 108, 101, 100, 58, 49, 13, 10, 97, 111, 102, 95, 114, 101, 119, 114, 105, 116, 101, 95, 105, 110, 95, 112, 114, 111, 103, 114, 101, 115, 115, 58, 48, 13, 10, 97, 111, 102, 95, 114, 101, 119, 114, 105, 116, 101, 95, 115, 99, 104, 101, 100, 117, 108, 101, 100, 58, 48, 13, 10, 97, 111, 102, 95, 108, 97, 115, 116, 95, 114, 101, 119, 114, 105, 116, 101, 95, 116, 105, 109, 101, 95, 115, 101, 99, 58, 45, 49, 13, 10, 97, 111, 102, 95, 99, 117, 114, 114, 101, 110, 116, 95, 114, 101, 119, 114, 105, 116, 101, 95, 116, 105, 109, 101, 95, 115, 101, 99, 58, 45, 49, 13, 10, 97, 111, 102, 95, 108, 97, 115, 116, 95, 98, 103, 114, 101, 119, 114, 105, 116, 101, 95, 115, 116, 97, 116, 117, 115, 58, 111, 107, 13, 10, 97, 111, 102, 95, 108, 97, 115, 116, 95, 119, 114, 105, 116, 101, 95, 115, 116, 97, 116, 117, 115, 58, 111, 107, 13, 10, 97, 111, 102, 95, 99, 117, 114, 114, 101, 110, 116, 95, 115, 105, 122, 101, 58, 55, 57, 13, 10, 97, 111, 102, 95, 98, 97, 115, 101, 95, 115, 105, 122, 101, 58, 48, 13, 10, 97, 111, 102, 95, 112, 101, 110, 100, 105, 110, 103, 95, 114, 101, 119, 114, 105, 116, 101, 58, 48, 13, 10, 97, 111, 102, 95, 98, 117, 102, 102, 101, 114, 95, 108, 101, 110, 103, 116, 104, 58, 48, 13, 10, 97, 111, 102, 95, 114, 101, 119, 114, 105, 116, 101, 95, 98, 117, 102, 102, 101, 114, 95, 108, 101, 110, 103, 116, 104, 58, 48, 13, 10, 97, 111, 102, 95, 112, 101, 110, 100, 105, 110, 103, 95, 98, 105, 111, 95, 102, 115, 121, 110, 99, 58, 48, 13, 10, 97, 111, 102, 95, 100, 101, 108, 97, 121, 101, 100, 95, 102, 115, 121, 110, 99, 58, 48, 13, 10, 13, 10, 35, 32, 83, 116, 97, 116, 115, 13, 10, 116, 111, 116, 97, 108, 95, 99, 111, 110, 110, 101, 99, 116, 105, 111, 110, 115, 95, 114, 101, 99, 101, 105, 118, 101, 100, 58, 49, 53, 53, 13, 10, 116, 111, 116, 97, 108, 95, 99, 111, 109, 109, 97, 110, 100, 115, 95, 112, 114, 111, 99, 101, 115, 115, 101, 100, 58, 54, 56, 50, 56, 49, 48, 51, 13, 10, 105, 110, 115, 116, 97, 110, 116, 97, 110, 101, 111, 117, 115, 95, 111, 112, 115, 95, 112, 101, 114, 95, 115, 101, 99, 58, 50, 50, 13, 10, 116, 111, 116, 97, 108, 95, 110, 101, 116, 95, 105, 110, 112, 117, 116, 95, 98, 121, 116, 101, 115, 58, 49, 49, 48, 57, 49, 50, 52, 54, 49, 13, 10, 116, 111, 116, 97, 108, 95, 110, 101, 116, 95, 111, 117, 116, 112, 117, 116, 95, 98, 121, 116, 101, 115, 58, 49, 52, 53, 54, 50, 56, 57, 52, 48, 53, 13, 10, 105, 110, 115, 116, 97, 110, 116, 97, 110, 101, 111, 117, 115, 95, 105, 110, 112, 117, 116, 95, 107, 98, 112, 115, 58, 48, 46, 51, 52, 13, 10, 105, 110, 115, 116, 97, 110, 116, 97, 110, 101, 111, 117, 115, 95, 111, 117, 116, 112, 117, 116, 95, 107, 98, 112, 115, 58, 51, 46, 49, 49, 13, 10, 114, 101, 106, 101, 99, 116, 101, 100, 95, 99, 111, 110, 110, 101, 99, 116, 105, 111, 110, 115, 58, 48, 13, 10, 115, 121, 110, 99, 95, 102, 117, 108, 108, 58, 48, 13, 10, 115, 121, 110, 99, 95, 112, 97, 114, 116, 105, 97, 108, 95, 111, 107, 58, 48, 13, 10, 115, 121, 110, 99, 95, 112, 97, 114, 116, 105, 97, 108, 95, 101, 114, 114, 58, 48, 13, 10, 101, 120, 112, 105, 114, 101, 100, 95, 107, 101, 121, 115, 58, 48, 13, 10, 101, 118, 105, 99, 116, 101, 100, 95, 107, 101, 121, 115, 58, 48, 13, 10, 107, 101, 121, 115, 112, 97, 99, 101, 95, 104, 105, 116, 115, 58, 48, 13, 10, 107, 101, 121, 115, 112, 97, 99, 101, 95, 109, 105, 115, 115, 101, 115, 58, 48, 13, 10, 112, 117, 98, 115, 117, 98, 95, 99, 104, 97, 110, 110, 101, 108, 115, 58, 48, 13, 10, 112, 117, 98, 115, 117, 98, 95, 112, 97, 116, 116, 101, 114, 110, 115, 58, 48, 13, 10, 108, 97, 116, 101, 115, 116, 95, 102, 111, 114, 107, 95, 117, 115, 101, 99, 58, 50, 56, 49, 13, 10, 109, 105, 103, 114, 97, 116, 101, 95, 99, 97, 99, 104, 101, 100, 95, 115, 111, 99, 107, 101, 116, 115, 58, 48, 13, 10, 13, 10, 35, 32, 82, 101, 112, 108, 105, 99, 97, 116, 105, 111, 110, 13, 10, 114, 111, 108, 101, 58, 109, 97, 115, 116, 101, 114, 13, 10, 99, 111, 110, 110, 101, 99, 116, 101, 100, 95, 115, 108, 97, 118, 101, 115, 58, 48, 13, 10, 109, 97, 115, 116, 101, 114, 95, 114, 101, 112, 108, 95, 111, 102, 102, 115, 101, 116, 58, 48, 13, 10, 114, 101, 112, 108, 95, 98, 97, 99, 107, 108, 111, 103, 95, 97, 99, 116, 105, 118, 101, 58, 48, 13, 10, 114, 101, 112, 108, 95, 98, 97, 99, 107, 108, 111, 103, 95, 115, 105, 122, 101, 58, 49, 48, 52, 56, 53, 55, 54, 13, 10, 114, 101, 112, 108, 95, 98, 97, 99, 107, 108, 111, 103, 95, 102, 105, 114, 115, 116, 95, 98, 121, 116, 101, 95, 111, 102, 102, 115, 101, 116, 58, 48, 13, 10, 114, 101, 112, 108, 95, 98, 97, 99, 107, 108, 111, 103, 95, 104, 105, 115, 116, 108, 101, 110, 58, 48, 13, 10, 13, 10, 35, 32, 67, 80, 85, 13, 10, 117, 115, 101, 100, 95, 99, 112, 117, 95, 115, 121, 115, 58, 50, 56, 54, 46, 53, 57, 13, 10, 117, 115, 101, 100, 95, 99, 112, 117, 95, 117, 115, 101, 114, 58, 50, 51, 56, 46, 49, 57, 13, 10, 117, 115, 101, 100, 95, 99, 112, 117, 95, 115, 121, 115, 95, 99, 104, 105, 108, 100, 114, 101, 110, 58, 48, 46, 48, 48, 13, 10, 117, 115, 101, 100, 95, 99, 112, 117, 95, 117, 115, 101, 114, 95, 99, 104, 105, 108, 100, 114, 101, 110, 58, 48, 46, 48, 48, 13, 10, 13, 10, 35, 32, 67, 108, 117, 115, 116, 101, 114, 13, 10, 99, 108, 117, 115, 116, 101, 114, 95, 101, 110, 97, 98, 108, 101, 100, 58, 48, 13, 10, 13, 10, 35, 32, 75, 101, 121, 115, 112, 97, 99, 101, 13, 10, 100, 98, 48, 58, 107, 101, 121, 115, 61, 49, 44, 101, 120, 112, 105, 114, 101, 115, 61, 48, 44, 97, 118, 103, 95, 116, 116, 108, 61, 48, 13, 10}
+ var nr int
+ {
+ fmt.Printf("TestCutRedisInfoSegment case %d.\n", nr)
+ nr++
+
+ expect := []byte{35, 32, 83, 101, 114, 118, 101, 114, 13, 10, 114, 101, 100, 105, 115, 95, 118, 101, 114, 115, 105, 111, 110, 58, 51, 46, 50, 46, 49, 49, 13, 10, 114, 101, 100, 105, 115, 95, 103, 105, 116, 95, 115, 104, 97, 49, 58, 100, 101, 49, 97, 100, 48, 50, 54, 13, 10, 114, 101, 100, 105, 115, 95, 103, 105, 116, 95, 100, 105, 114, 116, 121, 58, 48, 13, 10, 114, 101, 100, 105, 115, 95, 98, 117, 105, 108, 100, 95, 105, 100, 58, 54, 101, 49, 99, 101, 51, 55, 97, 102, 101, 48, 54, 99, 51, 52, 99, 13, 10, 114, 101, 100, 105, 115, 95, 109, 111, 100, 101, 58, 115, 116, 97, 110, 100, 97, 108, 111, 110, 101, 13, 10, 111, 115, 58, 76, 105, 110, 117, 120, 32, 51, 46, 49, 48, 46, 48, 45, 57, 53, 55, 46, 50, 49, 46, 51, 46, 101, 108, 55, 46, 120, 56, 54, 95, 54, 52, 32, 120, 56, 54, 95, 54, 52, 13, 10, 97, 114, 99, 104, 95, 98, 105, 116, 115, 58, 54, 52, 13, 10, 109, 117, 108, 116, 105, 112, 108, 101, 120, 105, 110, 103, 95, 97, 112, 105, 58, 101, 112, 111, 108, 108, 13, 10, 103, 99, 99, 95, 118, 101, 114, 115, 105, 111, 110, 58, 52, 46, 56, 46, 53, 13, 10, 112, 114, 111, 99, 101, 115, 115, 95, 105, 100, 58, 57, 48, 54, 57, 13, 10, 114, 117, 110, 95, 105, 100, 58, 49, 52, 49, 98, 51, 54, 101, 102, 50, 51, 50, 57, 56, 52, 53, 54, 98, 52, 100, 97, 101, 48, 49, 51, 49, 50, 57, 49, 98, 50, 100, 101, 99, 99, 101, 102, 102, 52, 54, 53, 13, 10, 116, 99, 112, 95, 112, 111, 114, 116, 58, 56, 53, 48, 51, 13, 10, 117, 112, 116, 105, 109, 101, 95, 105, 110, 95, 115, 101, 99, 111, 110, 100, 115, 58, 53, 56, 57, 54, 51, 49, 13, 10, 117, 112, 116, 105, 109, 101, 95, 105, 110, 95, 100, 97, 121, 115, 58, 54, 13, 10, 104, 122, 58, 49, 48, 13, 10, 108, 114, 117, 95, 99, 108, 111, 99, 107, 58, 51, 55, 52, 50, 48, 50, 48, 13, 10, 101, 120, 101, 99, 117, 116, 97, 98, 108, 101, 58, 47, 100, 97, 116, 97, 47, 109, 97, 112, 103, 111, 111, 47, 99, 111, 100, 105, 115, 47, 46, 47, 98, 105, 110, 47, 99, 111, 100, 105, 115, 45, 115, 101, 114, 118, 101, 114, 13, 10, 99, 111, 110, 102, 105, 103, 95, 102, 105, 108, 101, 58, 47, 100, 97, 116, 97, 47, 109, 97, 112, 103, 111, 111, 47, 99, 111, 100, 105, 115, 47, 46, 47, 99, 111, 100, 105, 115, 95, 115, 101, 114, 118, 101, 114, 47, 99, 111, 110, 102, 47, 114, 101, 100, 105, 115, 45, 56, 53, 48, 51, 46, 99, 111, 110, 102, 13, 10}
+ ret := CutRedisInfoSegment(input, "server")
+ assert.Equal(t, len(expect), len(ret), "should be equal")
+ assert.Equal(t, expect, ret, "should be equal")
+
+ ret = CutRedisInfoSegment(input, "SeRver")
+ assert.Equal(t, len(expect), len(ret), "should be equal")
+ assert.Equal(t, expect, ret, "should be equal")
}
- for _, c := range cases {
- result := HasAtLeastOnePrefix(c.key, c.prefixes)
- assert.Equal(t, c.expectResult, result)
+ {
+ fmt.Printf("TestCutRedisInfoSegment case %d.\n", nr)
+ nr++
+
+ expect := []byte{35, 32, 67, 108, 105, 101, 110, 116, 115, 13, 10, 99, 111, 110, 110, 101, 99, 116, 101, 100, 95, 99, 108, 105, 101, 110, 116, 115, 58, 52, 57, 13, 10, 99, 108, 105, 101, 110, 116, 95, 108, 111, 110, 103, 101, 115, 116, 95, 111, 117, 116, 112, 117, 116, 95, 108, 105, 115, 116, 58, 48, 13, 10, 99, 108, 105, 101, 110, 116, 95, 98, 105, 103, 103, 101, 115, 116, 95, 105, 110, 112, 117, 116, 95, 98, 117, 102, 58, 48, 13, 10, 98, 108, 111, 99, 107, 101, 100, 95, 99, 108, 105, 101, 110, 116, 115, 58, 48, 13, 10}
+ ret := CutRedisInfoSegment(input, "Clients")
+ assert.Equal(t, len(expect), len(ret), "should be equal")
+ assert.Equal(t, expect, ret, "should be equal")
}
-}
+}
\ No newline at end of file
diff --git a/src/redis-shake/filter/filter_test.go b/src/redis-shake/filter/filter_test.go
index dce0253..7709083 100644
--- a/src/redis-shake/filter/filter_test.go
+++ b/src/redis-shake/filter/filter_test.go
@@ -278,6 +278,38 @@ func TestHandleFilterKeyWithCommand(t *testing.T) {
}
}
+func TestHasAtLeastOnePrefix(t *testing.T) {
+ cases := []struct {
+ key string
+ prefixes []string
+ expectResult bool
+ }{
+ {
+ // no prefix provided
+ "a",
+ []string{},
+ false,
+ },
+ {
+ // has prefix
+ "abc",
+ []string{"ab"},
+ true,
+ },
+ {
+ // does NOT have prefix
+ "abc",
+ []string{"edf", "wab"},
+ false,
+ },
+ }
+
+ for _, c := range cases {
+ result := hasAtLeastOnePrefix(c.key, c.prefixes)
+ assert.Equal(t, c.expectResult, result)
+ }
+}
+
func convertToByte(args... string) [][]byte {
ret := make([][]byte, 0)
for _, arg := range args {