V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
such
V2EX  ›  Go 编程语言

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

  •  
  •   such ·
    8090lambert · 2019-09-30 17:35:47 +08:00 · 3874 次点击
    这是一个创建于 1663 天前的主题,其中的信息可能已经有所发展或是发生改变。

    go-redis-parser

    go-redis-parser,项目地址: https://github.com/8090Lambert/go-redis-parser 一个简单、安全的 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 文件的示例

    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
    
    4 条回复    2019-10-01 00:35:38 +08:00
    vus520
        1
    vus520  
       2019-09-30 18:52:43 +08:00
    之前用了一个 python 的分析工具,安装花了半天。就凭这一点,要给 go 写的点个赞。
    such
        2
    such  
    OP
       2019-09-30 19:24:47 +08:00
    @vus520 感谢支持,这个安装就是可执行二进制文件,如果觉得好用,麻烦顺手给个 star~
    scriptB0y
        3
    scriptB0y  
       2019-09-30 19:45:02 +08:00
    好东西 👍

    借楼也贴一下我最近在写的 reids 客户端: https://github.com/laixintao/iredis

    https://www.iredis.io/

    带语法高亮和自动补全。
    ericgui
        4
    ericgui  
       2019-10-01 00:35:38 +08:00
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1147 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 23:44 · PVG 07:44 · LAX 16:44 · JFK 19:44
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.