1. 程式人生 > >redis aof檔案解析成命令

redis aof檔案解析成命令

waoffle

A Redis AOF file parser. This module parses an AOF structure like this:

AOF檔案解析器。這個模組解析一個AOF結構是這樣的:

*3
$9
PEXPIREAT
$10
myRedisKey
$13
1719298712484
*3
$3
SET
$9
myJSONKey
$24
{"someKey": "someValue"}

... into raw Redis commands, like this:

生成命令列如下:

PEXPIREAT myRedisKey 1719298712484
SET myJSONKey {"someKey": "someValue"}

The opposite can also be achieved by using the reverse binary (rwaoffle) also provided in this module.

相反的也可以通過使用逆向二進位制(rwaoffle)也提供了在這個模組。

Installation/Usage

You can install this module via npm:

$ npm install -g waoffle

This installs a global binary waoffle to which you can use to pipe your syrup

 data to:

$ cat appendonly.aof | waoffle  # Pipe from other UNIX commands
$ waoffle < appendonly.aof      # or, pipe directly from stdin
$ waoffle appendonly.aof        # or, just specify the filename

Each of the three cases above are equivalent. The generated output will be streamed to stdout, to which you can dump into a file using redirection:

上面三種情況下是等價的。生成的輸出流傳送到stdout,你可以轉儲到一個檔案中使用重定向:

$ waoffle < appendonly.aof > generated_commands.txt

The reverse process—going from sets of operations to AOF format—can be achieved in the same manner by substituting calls towaoffle for rwaoffle.

Importing data into Redis

This is useful for importing data directly into a running Redis instance. Simply use the rwaoffle command if you are starting with a file full of operations. Even though Redis can already read its own AOF file format, this set of tools is even more powerful for filtering your AOF files:

這是用於將資料直接匯入到執行的複述例項。僅僅使用rwaoffle命令,如果你從一個檔案的操作。雖然複述,已經可以讀自己的AOF檔案格式,這組工具是更強大的過濾AOF檔案:

$ waoffle < appendonly.aof | grep SET | rwaoffle    # Only grab `SET` operations

Use this in combination with redis-cli --pipe for maximum win:

$ cat appendonly.aof | redis-cli --pipe             # Standard Redis import
$ cat commands.txt | rwaoffle | redis-cli --pipe    # Importing a list of commands
$ cat appendonly.aof | waoffle | grep SET \
      | rwaoffle | redis-cli --pipe                 # Import only `SET` operations
參考:https://github.com/nvite/waoffle