14 Star 47 Fork 10

Xie Biao / go-redis-memory-analysis

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Redis memory analysis

🔎 Analyzing memory of redis is to find the keys(prefix) which used a lot of memory, export the analysis result into csv file.

GoDoc Go Report Card Sourcegraph

Binary File Usage

  1. Download the appropriate binary file from Releases

  2. Run

# help
./redis-memory-analysis-linux-amd64 -h
Usage of ./redis-memory-analysis-darwin-amd64:
  -ip string
    	The host of redis (default "127.0.0.1")
  -password string
    	The password of redis (default "")
  -port uint
    	The port of redis (default 6379)
  -rdb string
    	The rdb file of redis (default "")
  -prefixes string
    	The prefixes list of redis key, be split by '//', special pattern characters need to escape by '\' (default "#//:")
  -reportPath string
    	The csv file path of analysis result (default "./reports")

# run by connecting to redis
./redis-memory-analysis-linux-amd64 -ip="127.0.0.1" -port=6380 -password="abc" -prefixes="#//:"

# run by redis rdb file
./redis-memory-analysis-linux-amd64 -rdb="./6379_dump.rdb" -prefixes="#//:"

Source Code Usage

  1. Install
//cd your-root-folder-of-project
// dep init
dep ensure -add github.com/hhxsv5/go-redis-memory-analysis@~2.0.0
  1. Run
  • Analyze keys by connecting to redis directly.
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("something wrong:", err)
    return
}

//Scan the keys which can be split by '#' ':'
//Special pattern characters need to escape by '\'
analysis.Start([]string{"#", ":"})

//Find the csv file in default target folder: ./reports
//CSV file name format: redis-analysis-{host:port}-{db}.csv
//The keys order by count desc
err = analysis.SaveReports("./reports")
if err == nil {
    fmt.Println("done")
} else {
    fmt.Println("error:", err)
}
  • Analyze keys by redis RDB file, but cannot work out the size of key.
analysis := NewAnalysis()
//Open redis rdb file: ./6379_dump.rdb
err := analysis.OpenRDB("./6379_dump.rdb")
defer analysis.CloseRDB()
if err != nil {
    fmt.Println("something wrong:", err)
    return
}

//Scan the keys which can be split by '#' ':'
//Special pattern characters need to escape by '\'
analysis.StartRDB([]string{"#", ":"})

//Find the csv file in default target folder: ./reports
//CSV file name format: redis-analysis-{host:port}-{db}.csv
//The keys order by count desc
err = analysis.SaveReports("./reports")
if err == nil {
    fmt.Println("done")
} else {
    fmt.Println("error:", err)
}

CSV

Another tool implemented by PHP

redis-memory-analysis

License

MIT

MIT License Copyright (c) 2017 Dave Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

Go 实现的 Redis 内存分析工具:用于找出占用内存较多的 Key,将结果导出至 CSV 文件。 展开 收起
Go
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Go
1
https://gitee.com/hhxsv5/go-redis-memory-analysis.git
git@gitee.com:hhxsv5/go-redis-memory-analysis.git
hhxsv5
go-redis-memory-analysis
go-redis-memory-analysis
master

搜索帮助