-
Notifications
You must be signed in to change notification settings - Fork 711
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix bug of 'rump' mode only syncing db 0 data
- Loading branch information
Showing
5 changed files
with
133 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package utils | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"strconv" | ||
) | ||
|
||
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)) | ||
} | ||
|
||
lines := bytes.Split(content, []byte("\n")) | ||
reply := make(map[int32]int64) | ||
for _, line := range lines { | ||
line = bytes.TrimSpace(line) | ||
if bytes.HasPrefix(line, []byte("db")) == true { | ||
// line "db0:keys=18,expires=0,avg_ttl=0" | ||
items := bytes.Split(line, []byte(":")) | ||
db, err := strconv.Atoi(string(items[0][2:])) | ||
if err != nil { | ||
return nil, err | ||
} | ||
nums := bytes.Split(items[1], []byte(",")) | ||
if bytes.HasPrefix(nums[0], []byte("keys=")) == false { | ||
return nil, fmt.Errorf("invalid info Keyspace: %s", string(content)) | ||
} | ||
keysNum, err := strconv.ParseInt(string(nums[0][5:]), 10, 0) | ||
if err != nil { | ||
return nil, err | ||
} | ||
reply[int32(db)] = int64(keysNum) | ||
} // end true | ||
} // end for | ||
return reply, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters