点击上方蓝色“Go语言中文网”关注,每天一起学 Go本文是使用 golang 实现 redis 系列的第四篇文章,将介绍如何使用 golang 实现 Append Only File 持久化及 AOF 文件重写。本文完整源代码在作者Github:https://github.com/HDT3213/godis/blob/master/src/db/aof.goAOF 文件 AOF 持久化是典型的异步任务,主协程(goroutine) 可以使用 channel 将数据发送到异步协程由异步协程执行持久化操作。在 DB 中定义相关字段:type DB struct { // 主线程使用此channel将要持久化的命令发送到异步协程 aofChan chan *reply.MultiBulkReply // append file 文件描述符 aofFile *os.File // append file 路径 aofFilename string // aof 重写需要的缓冲区,将在AOF重写一节详细介绍 aofRewriteChan
………………………………