An Embedded Key/Value Store for Shell Scripts
Contents
UPDATE: this is now available as a sub command, here: kiev
Cooked this up last night when I needed a simple key/value store for use in a shell script:
|
|
Use it like so:
$ ./db.sh set foo bar
$ ./db.sh get foo
$ ./db.sh set foo baz
$ ./db.sh get foo
$ ./db.sh del foo
$ ./db.sh list
How it works
Every time you update/set/delete a value, it writes a shell expression to an append-only log, exporting a shell variable (key) with that value. By sourcing the file every time we read a value, we replay the log, bringing our environment to a consistent state. Then, reading the value is just looking up that dynamic variable (key) in our shell environment.