Awesome
wal
Package wal implements write-ahead logging.
Feature
- Low memory usage
- Segment
- Batch writes
- Clean/Truncate/Reset
Get started
Install
go get github.com/hslam/wal
Import
import "github.com/hslam/wal"
Usage
Example
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()
}
Output
Hello World
License
This package is licensed under a MIT license (Copyright (c) 2020 Meng Huang)
Author
wal was written by Meng Huang.