File tree Expand file tree Collapse file tree 3 files changed +28
-14
lines changed Expand file tree Collapse file tree 3 files changed +28
-14
lines changed Original file line number Diff line number Diff line change @@ -11,21 +11,21 @@ Analyzing memory of redis is to find the keys(prefix) which used a lot of memory
1111//cd your-root-folder-of-project
1212//Create the file glide.yaml if not exist
1313//touch glide.yaml
14- glide get github.com/hhxsv5/go-redis-memory-analysis#~1.1 .0
14+ glide get github.com/hhxsv5/go-redis-memory-analysis#~2.0 .0
1515//glide: THANK GO15VENDOREXPERIMENT
1616` ` `
1717
18182. Run
1919
2020` ` ` Go
21- redis, err := NewRedisClient(" 127.0.0.1" , 6379, " " )
21+ analysis := NewAnalysis ()
22+ //Open redis: 127.0.0.1:6379 without password
23+ err := analysis.Open(" 127.0.0.1" , 6379, " " )
24+ defer analysis.Close ()
2225if err ! = nil {
23- fmt.Println(" connect redis fail " , err)
26+ fmt.Println(" something wrong: " , err)
2427 return
2528}
26- defer redis.Close ()
27-
28- analysis := NewAnalysis(redis)
2929
3030//Scan the keys which can be split by ' #' ' :'
3131//Special pattern characters need to escape by ' \'
Original file line number Diff line number Diff line change @@ -40,8 +40,23 @@ func (sr SortReports) Swap(i, j int) {
4040 sr [i ], sr [j ] = sr [j ], sr [i ]
4141}
4242
43- func NewAnalysis (redis * RedisClient ) * Analysis {
44- return & Analysis {redis , DBReports {}}
43+ func NewAnalysis () * Analysis {
44+ return & Analysis {nil , DBReports {}}
45+ }
46+
47+ func (analysis * Analysis ) Open (host string , port uint16 , password string ) error {
48+ redis , err := NewRedisClient (host , port , password )
49+ if err != nil {
50+ return err
51+ }
52+ analysis .redis = redis
53+ return nil
54+ }
55+
56+ func (analysis * Analysis ) Close () {
57+ if analysis .redis != nil {
58+ analysis .redis .Close ()
59+ }
4560}
4661
4762func (analysis Analysis ) Start (delimiters []string ) {
Original file line number Diff line number Diff line change @@ -3,18 +3,17 @@ package main
33import (
44 "fmt"
55 . "github.com/hhxsv5/go-redis-memory-analysis"
6- . "github.com/hhxsv5/go-redis-memory-analysis/storages"
76)
87
98func main () {
10- redis , err := NewRedisClient ("127.0.0.1" , 6379 , "" )
9+ analysis := NewAnalysis ()
10+ //Open redis: 127.0.0.1:6379 without password
11+ err := analysis .Open ("127.0.0.1" , 6379 , "" )
12+ defer analysis .Close ()
1113 if err != nil {
12- fmt .Println ("connect redis fail " , err )
14+ fmt .Println ("something wrong: " , err )
1315 return
1416 }
15- defer redis .Close ()
16-
17- analysis := NewAnalysis (redis )
1817
1918 //Scan the keys which can be split by '#' ':'
2019 //Special pattern characters need to escape by '\'
You can’t perform that action at this time.
0 commit comments