Skip to content

Commit

Permalink
Initial implementation (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg authored Sep 13, 2023
1 parent fea21e3 commit 02209f2
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 1 deletion.
18 changes: 18 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: 2
updates:
- package-ecosystem: "gomod"
commit-message:
prefix: "deps:"
directory: "/"
schedule:
interval: "weekly"
day: "sunday"
time: "09:00"
- package-ecosystem: "github-actions"
commit-message:
prefix: "ci:"
directory: "/"
schedule:
interval: "weekly"
day: "sunday"
time: "09:00"
17 changes: 17 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: build

on:
push:
branches: [main]
pull_request:
branches: [main]
schedule:
- cron: '0 0 * * 0' # run "At 00:00 on Sunday"

# See https://github.com/cristalhq/.github/
jobs:
build:
uses: cristalhq/.github/.github/workflows/[email protected]

vuln:
uses: cristalhq/.github/.github/workflows/[email protected]
1 change: 1 addition & 0 deletions GUIDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Guide for kvstore
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,41 @@
# kvstore
Key-value store abstraction in Go

[![build-img]][build-url]
[![pkg-img]][pkg-url]
[![version-img]][version-url]

Key-value store abstraction in Go.

## Features

* Simple.
* Dependency-free.

See [docs][pkg-url] and [GUIDE.md](https://github.com/go-distsys/kvstore/blob/main/GUIDE.md) for more details.

## Install

Go version 1.18+

```
go get github.com/go-distsys/kvstore
```

## Example

```go
TODO
```

See [example_test.go](https://github.com/go-distsys/kvstore/blob/main/example_test.go).

## License

[MIT License](LICENSE).

[build-img]: https://github.com/go-distsys/kvstore/workflows/build/badge.svg
[build-url]: https://github.com/go-distsys/kvstore/actions
[pkg-img]: https://pkg.go.dev/badge/go-distsys/kvstore
[pkg-url]: https://pkg.go.dev/github.com/go-distsys/kvstore
[version-img]: https://img.shields.io/github/v/release/go-distsys/kvstore
[version-url]: https://github.com/go-distsys/kvstore/releases
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/go-distsys/kvstore

go 1.18
38 changes: 38 additions & 0 deletions kvstore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package kvstore

import (
"context"
"errors"
)

// Store represents the key-value storage.
type Store interface {
Put(ctx context.Context, key string, value []byte) error
Get(ctx context.Context, key string) (*Pair, error)
Delete(ctx context.Context, key string) error
Exists(ctx context.Context, key string) (bool, error)
}

// AtomicStore represents the key-value storage that supports atomic operations.
type AtomicStore interface {
AtomicPut(ctx context.Context, key string, value []byte, prev *Pair) (bool, *Pair, error)
AtomicGet(ctx context.Context, key string) (*Pair, error)
AtomicDelete(ctx context.Context, key string, prev *Pair) (bool, error)
}

// WatchStore represents the key-value storage that supports watch operations.
type WatchStore interface {
Watch(ctx context.Context, key string) (<-chan *Pair, error)
WatchTree(ctx context.Context, prefix string) (<-chan []*Pair, error)
}

// Pair stored in key-value storage.
type Pair struct {
Key string
Value []byte
}

// Key-value storage errors.
var (
ErrKeyNotFound = errors.New("key not found")
)

0 comments on commit 02209f2

Please sign in to comment.