25

go-redis-parser(高效的Redis解析工具,支持查找大 key)

 4 years ago
source link: https://www.tuicool.com/articles/Y36jiab
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Ib2Yzqi.png!web

go-redis-parser ,项目地址: https://github.com/8090Lamber... 一个简单、安全的Redis 解析器。了解到目前存在的 parser,大部分都是单进程解析完成后,再统一输出,拉长了整体的执行时间,决定自己重写一个。它的特点是: 离线即用 ,不必连接线上服务,并且利用 golang 语言本身的协程, 实现边解析边写文件内容,非常高效

简单介绍下这个工具:

Feature

支持Redis从2.8版本至5.0版本的,除了 module 外的所有数据类型。包括:

  • String
  • Hash
  • List
  • Set
  • SortedSed
  • Stream(敲黑板,重点重点重点,重要的事情说三遍)

Other

导出 server 所有 key/values,而且会找出现有各类型的 bigkey (类似 redis-cli 的 --bigkeys 参数输出)

Installation

go-redis-parser 是可执行的二进制文件( binary file ),可以使用 git 或者 go get 来下载安装

via git

$ git clone https://github.com/8090Lambert/go-redis-parser.git && cd go-redis-parser
$ go install

via go

$ go get github.com/8090Lambert/go-redis-parser

Using

在使用之前,你需要先设置 export PATH=$PATH:$GOPATH/bin

$ go-redis-parser -rdb <dump.rdb> -o <gen-file folder> -type <gen-file type, json or csv, default csv>

Generate file

目前可导出两种类型的文件:json、csv。这里看下 csv 文件的示例

f2Avi23.png!web

BigKeys outputs

BigKeys的输出示例:

# Scanning the rdb file to find biggest keys

-------- summary -------

Sampled 6 keys in the keyspace!
Total key length in bytes is 17

Biggest string found 's' has 1 bytes
Biggest   hash found 'h' has 1 fields
Biggest   list found 'li' has 2 items
Biggest sortedset found 'zset' has 2 members
Biggest    set found 'set' has 2 members
Biggest stream found 'stream' has 3 entries

1 string with 1 bytes
1 hash with 1 fields
1 list with 2 items
1 sortedset with 2 members
1 set with 2 members
1 stream with 3 entries

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK