Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ostafen/rocketdb
Distributed transactional key value store backed by Redis.
https://github.com/ostafen/rocketdb
database distributed-database golang in-memory-caching in-memory-database key-value-store redis transaction transactions
Last synced: 3 months ago
JSON representation
Distributed transactional key value store backed by Redis.
- Host: GitHub
- URL: https://github.com/ostafen/rocketdb
- Owner: ostafen
- Created: 2023-04-16T15:54:49.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-04-17T13:23:45.000Z (over 1 year ago)
- Last Synced: 2024-06-21T18:52:51.085Z (7 months ago)
- Topics: database, distributed-database, golang, in-memory-caching, in-memory-database, key-value-store, redis, transaction, transactions
- Language: Go
- Homepage:
- Size: 5.86 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# RocketDB :rocket:
# Motivations
Redis approach to transactions is based on a check-and-set (**CAS**) behavior provided by the **WATCH** command, which accepts a list of keys. The **WATCH** command is usually followed by a **MULTI**-**EXEC** block, which is only executed if any of the watched keys has been modified in the meantime by any other concurrent transaction. For example:
```
WATCH mykey
val = GET mykey
val = val + 1
MULTI
SET mykey $val
EXEC
```While **WATCH** can be called multiple times before the committing the transaction, serializability can be achieved only if the full set of keys to be watched is known in advance and passed to the first **WATCH** call.
**RocketDB** is meant to unlock the full power of Redis transactions while providing an easy to use interface.
# Installation
To start using RocketDB, type the following command:
```bash
$ go get -u github.com/ostafen/rocketdb
```# Opening a database
```go
import (
"github.com/ostafen/rocketdb"
)const (
host = "localhost"
port = 6379
)func main() {
db, err := rocketdb.New(redis.NewClient(&redis.Options{
Addr: fmt.Sprintf("%s:%d", host, port),
Password: "",
DB: 0,
}))
if err != nil {
log.Fatal(err)
}
defer db.Close()...
}
```# Transactions
The easiest way to start a new (read-write) transaction is to use the `Update()` method
```go
err := db.Update(func(tx *rocketdb.Tx) error {
...
tx.Set("key", "value")
...
tx.Remove("key1")
return nil
})
```or, for read-only transactions, the `View()` method:
```go
err := db.View(func(tx *rocketdb.Tx) error {
...
value, _ := tx.Get("key")
...
return nil
})
```Sometimes you may want to take care of transaction managment. In those cases, you can use the `Begin()` method to get a new transaction:
```go
tx, err := db.Begin(context.Background(), true) // start a new writable transaction with the provided context
if err != nil {
return err
}
...
```# Contact
Stefano Scafiti @ostafen
# Licence
RocketDB source code is available under the **MIT License**.