Documentation
¶
Overview ¶
Package storage implements a simple Key Value Storage system with nested transaction capabilities.
Example ¶
package main
import (
"fmt"
"github.com/caasmo/kv-repl-barebones/storage"
)
func main() {
cases := []struct {
cmd string
key string
val string
}{
{cmd: "write", key: "a", val: "hi"},
{cmd: "read", key: "a", val: ""},
{cmd: "begin", key: "", val: ""},
{cmd: "read", key: "a", val: ""},
{cmd: "write", key: "a", val: "bye"},
{cmd: "read", key: "a", val: ""},
{cmd: "begin", key: "", val: ""},
{cmd: "remove", key: "a", val: ""},
{cmd: "read", key: "a", val: ""},
{cmd: "commit", key: "", val: ""},
{cmd: "read", key: "a", val: ""},
{cmd: "write", key: "a", val: "bye now"},
{cmd: "read", key: "a", val: ""},
{cmd: "discard", key: "", val: ""},
{cmd: "read", key: "a", val: ""},
}
store := storage.NewStore()
for _, tc := range cases {
v, err := store.Process(tc.cmd, tc.key, tc.val)
if len(v) > 0 {
fmt.Printf("%s\n", v)
}
if err != nil {
fmt.Printf("%s\n", err)
}
}
}
Output: hi hi bye Key not found: a Key not found: a bye now hi
Index ¶
Examples ¶
Constants ¶
View Source
const ( // Supported commands Write = "write" Read = "read" Remove = "remove" Begin = "begin" Commit = "commit" Discard = "discard" )
Variables ¶
Functions ¶
This section is empty.
Types ¶
Click to show internal directories.
Click to hide internal directories.