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
11
11
//cd your-root-folder-of-project
12
12
//Create the file glide.yaml if not exist
13
13
//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
15
15
//glide: THANK GO15VENDOREXPERIMENT
16
16
` ` `
17
17
18
18
2. Run
19
19
20
20
` ` ` 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 ()
22
25
if err ! = nil {
23
- fmt.Println(" connect redis fail " , err)
26
+ fmt.Println(" something wrong: " , err)
24
27
return
25
28
}
26
- defer redis.Close ()
27
-
28
- analysis := NewAnalysis(redis)
29
29
30
30
//Scan the keys which can be split by ' #' ' :'
31
31
//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) {
40
40
sr [i ], sr [j ] = sr [j ], sr [i ]
41
41
}
42
42
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
+ }
45
60
}
46
61
47
62
func (analysis Analysis ) Start (delimiters []string ) {
Original file line number Diff line number Diff line change @@ -3,18 +3,17 @@ package main
3
3
import (
4
4
"fmt"
5
5
. "github.com/hhxsv5/go-redis-memory-analysis"
6
- . "github.com/hhxsv5/go-redis-memory-analysis/storages"
7
6
)
8
7
9
8
func 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 ()
11
13
if err != nil {
12
- fmt .Println ("connect redis fail " , err )
14
+ fmt .Println ("something wrong: " , err )
13
15
return
14
16
}
15
- defer redis .Close ()
16
-
17
- analysis := NewAnalysis (redis )
18
17
19
18
//Scan the keys which can be split by '#' ':'
20
19
//Special pattern characters need to escape by '\'
You can’t perform that action at this time.
0 commit comments