wal

package module
v0.0.0-...-88edd86 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2024 License: MIT Imports: 6 Imported by: 0

README

WAL

A simple Write-Ahead-Log built on LevelDB.

Using LevelDB gives several benefits without writing any additional code, like compression and compaction. See LevelDB for more details.

Usage


package main

import (
	"github.com/althk/wal"
)

func main() {
	wal, err := wal.New("/path/to/db")
	if err != nil {
		// handle error
    }
	defer wal.Close()
	
	err = wal.Put("key1", []byte("val1"))
	err = wal.PutBatch(
		map[string][]byte{
			"key2", []byte(100),
			"key3", []byte(false),
			"prefix_a", []byte("a"),
			"prefix_b", []byte("b"),
		}
	)
	
	for k, v := wal.Entries() {
	    fmt.Printf("k=%v, v=%v\n", k, v)	
    }
}

Documentation

Overview

Package wal provides a simple interface for a write-ahead-log built on top of LevelDB

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrKeyNotFound = errors.New("key not found")
)

Functions

This section is empty.

Types

type WAL

type WAL struct {
	// contains filtered or unexported fields
}

WAL provides a write-ahead-log built over LevelDB

func New

func New(path string) (*WAL, error)

New initializes a new WAL service with a LevelDB created at the given dir path. It is an error if the dir path already exists.

func (*WAL) Close

func (wal *WAL) Close() error

func (*WAL) Delete

func (wal *WAL) Delete(key string) error

func (*WAL) Entries

func (wal *WAL) Entries() iter.Seq2[string, []byte]

Entries returns an iterator that can be used in range loops to iterate over all entries of the WAL.

func (*WAL) EntriesBetween

func (wal *WAL) EntriesBetween(start, end string) iter.Seq2[string, []byte]

EntriesBetween returns an iterator that returns entries between the given set of keys. It is an open interval - the returned entries include the key 'start' and upto, but excluding the key 'end'.

func (*WAL) EntriesWithPrefix

func (wal *WAL) EntriesWithPrefix(prefix string) iter.Seq2[string, []byte]

EntriesWithPrefix returns an iterator that returns entries that match the given prefix.

func (*WAL) Get

func (wal *WAL) Get(key string) ([]byte, error)

func (*WAL) Put

func (wal *WAL) Put(key string, value []byte) error

func (*WAL) PutBatch

func (wal *WAL) PutBatch(entries map[string][]byte) error

PutBatch writes multiple entries in one batch, which is more efficient than writing multiple entries one at a time.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL