|
| 1 | +# file_writer |
| 2 | + |
| 3 | +## Introduction |
| 4 | + |
| 5 | +Can use ` file_writer ` to write data to file with type CMD/JSON/AOF . |
| 6 | +It is commonly used to extract/migrate/fix data by file. |
| 7 | + |
| 8 | +## configuration |
| 9 | + |
| 10 | +```toml |
| 11 | +[file_writer] |
| 12 | +filepath = "/tmp/cmd.txt" |
| 13 | +type = "cmd" #cmd,aof,json (default cmd) |
| 14 | +``` |
| 15 | + |
| 16 | +* An absolute filepath should be passed in. |
| 17 | +## application scenarios |
| 18 | +- share data between two system: one system write aof to disk/s3/oss, another system read file from them. |
| 19 | +- partial migrate data with business prefix: extract aof with prefix "XXX:" data from A system, B system import the aof with command `redis-cli --pipe XXX.aof` . |
| 20 | +- fix data by cmd file: export cmd data from one system, fix wrong data, and then import cmd file with command `redis-cli < cmd.txt`. |
| 21 | +- analysis data with json: export json file, and then import them into mongodb/bi to analysis. |
| 22 | + |
| 23 | +## example output: |
| 24 | +### cmd_writer output: |
| 25 | +``` |
| 26 | +SELECT 0 |
| 27 | +set key1 1 |
| 28 | +set key2 2 |
| 29 | +set key3 3 |
| 30 | +sadd key4 1 2 3 4 |
| 31 | +lpush key5 1 2 3 4 5 |
| 32 | +zadd key6 1 2 3 4 5 6 |
| 33 | +``` |
| 34 | +### json_writer output: |
| 35 | +``` |
| 36 | +{"DbId":0,"Argv":["SELECT","0"],"CmdName":"SELECT","Group":"CONNECTION","Keys":null,"KeyIndexes":null,"Slots":[],"SerializedSize":23} |
| 37 | +{"DbId":0,"Argv":["set","key1","1"],"CmdName":"SET","Group":"STRING","Keys":["key1"],"KeyIndexes":[2],"Slots":[9189],"SerializedSize":30} |
| 38 | +{"DbId":0,"Argv":["set","key2","2"],"CmdName":"SET","Group":"STRING","Keys":["key2"],"KeyIndexes":[2],"Slots":[4998],"SerializedSize":30} |
| 39 | +{"DbId":0,"Argv":["set","key3","3"],"CmdName":"SET","Group":"STRING","Keys":["key3"],"KeyIndexes":[2],"Slots":[935],"SerializedSize":30} |
| 40 | +{"DbId":0,"Argv":["sadd","key4","1","2","3","4"],"CmdName":"SADD","Group":"SET","Keys":["key4"],"KeyIndexes":[2],"Slots":[13120],"SerializedSize":52} |
| 41 | +{"DbId":0,"Argv":["lpush","key5","1","2","3","4","5"],"CmdName":"LPUSH","Group":"LIST","Keys":["key5"],"KeyIndexes":[2],"Slots":[9057],"SerializedSize":60} |
| 42 | +{"DbId":0,"Argv":["zadd","key6","1","2","3","4","5","6"],"CmdName":"ZADD","Group":"SORTED_SET","Keys":["key6"],"KeyIndexes":[2],"Slots":[4866],"SerializedSize":66} |
| 43 | +``` |
| 44 | +### aof_writer output: |
| 45 | +``` |
| 46 | +*2 |
| 47 | +$6 |
| 48 | +SELECT |
| 49 | +$1 |
| 50 | +0 |
| 51 | +*3 |
| 52 | +$3 |
| 53 | +set |
| 54 | +$4 |
| 55 | +key1 |
| 56 | +$1 |
| 57 | +1 |
| 58 | +``` |
0 commit comments