Skip to content

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zkv

zkv is a small key-value store written in Zig. It runs as a REPL, keeps data in memory, and persists mutations to an append-only log file.

Requirements

  • Zig 0.16.0

Run

zig build run

Commands

put <key> <value>  store value under key
get <key>          print value for key
del <key>          delete key
exists <key>       print whether key exists
count              print number of keys
keys               print all keys
dump               print all key-value pairs
clear              delete all keys
compact            rewrite log to current engine state
help               show help
exit               quit

Keys are single tokens and cannot contain whitespace. Values are stored as the rest of the line, so spaces are allowed:

put greeting hello world
get greeting

Persistence

zkv writes successful mutations to zkv.log in the current working directory:

put name ashish
del name
clear

On startup, the log is replayed into the in-memory engine before the REPL starts. Reads and non-mutating commands are not written to the log.

Run compact to rewrite the log so it contains only the current engine state. This removes stale put and del entries from earlier sessions.

The log format is intentionally simple for now. It assumes keys do not contain whitespace and values do not contain newlines.

Test

zig build test

Project Structure

src/engine.zig  in-memory key-value engine
src/parser.zig  REPL command parser
src/log.zig     append-only log and replay
src/repl.zig    REPL loop and command execution
src/main.zig    application entrypoint

About

A simple in-memory kv store with append only logs written in Zig.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages