Package wal implements write-ahead logging.
- Low memory usage
- Segment
- Batch writes
- Clean/Truncate/Reset
go get github.com/hslam/wal
import "github.com/hslam/wal"
package main
import (
"fmt"
"github.com/hslam/wal"
"os"
)
func main() {
path := "wal"
os.RemoveAll(path)
w, err := wal.Open(path, &wal.Options{SegmentEntries: 3})
if err != nil {
panic(err)
}
defer w.Close()
// Write
w.Write(1, []byte("Hello World"))
w.Flush()
w.Sync()
// Batch Write
w.Write(2, []byte("Hello WAL"))
w.Write(3, []byte("Hello MH"))
w.Flush()
w.Sync()
data, _ := w.Read(1)
fmt.Println(string(data))
w.Clean(2)
w.Truncate(2)
w.Reset()
}
Hello World
This package is licensed under a MIT license (Copyright (c) 2020 Meng Huang)
wal was written by Meng Huang.