Skip to content

Commit

Permalink
2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
XieBiao committed Jan 2, 2018
1 parent 0f4e03e commit 947744c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ Analyzing memory of redis is to find the keys(prefix) which used a lot of memory
//cd your-root-folder-of-project
//Create the file glide.yaml if not exist
//touch glide.yaml
glide get github.com/hhxsv5/go-redis-memory-analysis#~1.1.0
glide get github.com/hhxsv5/go-redis-memory-analysis#~2.0.0
//glide: THANK GO15VENDOREXPERIMENT
```
2. Run
```Go
redis, err := NewRedisClient("127.0.0.1", 6379, "")
analysis := NewAnalysis()
//Open redis: 127.0.0.1:6379 without password
err := analysis.Open("127.0.0.1", 6379, "")
defer analysis.Close()
if err != nil {
fmt.Println("connect redis fail", err)
fmt.Println("something wrong:", err)
return
}
defer redis.Close()

analysis := NewAnalysis(redis)

//Scan the keys which can be split by '#' ':'
//Special pattern characters need to escape by '\'
Expand Down
19 changes: 17 additions & 2 deletions analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,23 @@ func (sr SortReports) Swap(i, j int) {
sr[i], sr[j] = sr[j], sr[i]
}

func NewAnalysis(redis *RedisClient) *Analysis {
return &Analysis{redis, DBReports{}}
func NewAnalysis() *Analysis {
return &Analysis{nil, DBReports{}}
}

func (analysis *Analysis) Open(host string, port uint16, password string) error {
redis, err := NewRedisClient(host, port, password)
if err != nil {
return err
}
analysis.redis = redis
return nil
}

func (analysis *Analysis) Close() {
if analysis.redis != nil {
analysis.redis.Close()
}
}

func (analysis Analysis) Start(delimiters []string) {
Expand Down
11 changes: 5 additions & 6 deletions examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@ package main
import (
"fmt"
. "github.com/hhxsv5/go-redis-memory-analysis"
. "github.com/hhxsv5/go-redis-memory-analysis/storages"
)

func main() {
redis, err := NewRedisClient("127.0.0.1", 6379, "")
analysis := NewAnalysis()
//Open redis: 127.0.0.1:6379 without password
err := analysis.Open("127.0.0.1", 6379, "")
defer analysis.Close()
if err != nil {
fmt.Println("connect redis fail", err)
fmt.Println("something wrong:", err)
return
}
defer redis.Close()

analysis := NewAnalysis(redis)

//Scan the keys which can be split by '#' ':'
//Special pattern characters need to escape by '\'
Expand Down

0 comments on commit 947744c

Please sign in to comment.