MemoryLaneDB is a high-performance, embedded key-value store written in Go. It follows the Bitcask design pattern, providing fast read/write operations with a simple and reliable storage model.
- Simple API: Easy-to-use key-value operations (Put, Get, Delete)
- High Performance: All keys are stored in memory for fast lookups
- Durability: Append-only log structure ensures data durability
- Crash Recovery: Fast recovery with optional hint files
- Data Compaction: Automatic merging of data files to reclaim space
- Data Integrity: Checksums to ensure data is not corrupted
- Concurrent Access Protection: File locking to prevent multiple processes from accessing the same database
MemoryLaneDB follows the Bitcask design pattern:
- Log-Structured Storage: Data is stored in append-only log files (datafiles)
- In-Memory Index: All keys are kept in memory for fast lookups
- Compaction: Periodic merging of files to reclaim space from deleted or updated entries
- Hint Files: Optional files to speed up database recovery
- Go 1.18 or higher
Clone the repository and build the command-line tool:
git clone https://github.com/sarkk0x0/memorylanedb.git
cd memorylanedb
make build
This will create the mlctl
binary in the bin
directory.
MemoryLaneDB comes with a command-line tool (mlctl
) for basic operations:
mlctl is a tool for inspecting memorylane databases.
Usage:
mlctl command [arguments]
The commands are:
put insert a key-value pair in the db
get retrieve value of a key
list list all keys in the db
info print basic info
help print this screen
stats generate usage stats
Use "mlctl [command] -h" for more information about a command.
./bin/mlctl put mykey "my value"
./bin/mlctl get mykey
./bin/mlctl list
MemoryLaneDB can also be used as a library in your Go applications:
package main
import (
"fmt"
mdb "github.com/sarkk0x0/memorylanedb"
)
func main() {
// Open or create a database
db, err := mdb.NewDB("/path/to/db", nil)
if err != nil {
panic(err)
}
defer db.Close()
// Store a key-value pair
err = db.Put(mdb.Key("mykey"), []byte("my value"))
if err != nil {
panic(err)
}
// Retrieve a value
value, err := db.Get(mdb.Key("mykey"))
if err != nil {
panic(err)
}
fmt.Printf("Value: %s\n", value)
}
NewDB(path string, opts *Option) (*DB, error)
: Create or open a databaseDB.Put(key Key, value []byte) error
: Store a key-value pairDB.Get(key Key) ([]byte, error)
: Retrieve a value by keyDB.Has(key Key) (bool, error)
: Check if a key existsDB.Delete(key Key) error
: Delete a key-value pairDB.Fold(f foldFunc) error
: Iterate over all keysDB.Close() error
: Close the database
Contributions are welcome! Please feel free to submit a Pull Request.