Last updated
Last updated
*N is the number of arguments of the command.
$M is the length, i.e. the number of bytes, of each argument.
#!/usr/bin/python
# coding=utf8
"""
# Author: wangbin34
# Created Time : 2022-08-09 17:13:04
# File Name: aof_parse.py
# Description:
*N 是命令的参数个数
$M 是每个参数的长度,即字节数。
size 为命令开始字节数
"""
start_size = 0
end_size = 0
command_aof_size = 0
command = ""
with open("./appendonly.aof_bak") as f:
for line in f:
if line.startswith("*"):
end_size = start_size + command_aof_size
# 输出上条命令
print "start_size={start_size}, end_size={end_size} command=[{command} ]".format(start_size=start_size,
end_size=end_size, command=command)
# 开始统计下一条命令
start_size = start_size + command_aof_size
command = ""
command_aof_size = 0
command_aof_size = command_aof_size + len(line)
continue
command_aof_size = command_aof_size + len(line)
if line.startswith("$"):
continue
command = command + " " + line.strip()
# 最后一条命令
end_size = start_size + command_aof_size
# 输出上条命令
print "start_size={start_size}, end_size={end_size} command=[{command} ]".format(start_size=start_size,
end_size=end_size, command=command)