Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bsm/cdb64
cdb golang key-value key-value-store
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/bsm/cdb64
- Owner: bsm
- License: mit
- Created: 2019-06-30T11:13:38.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2023-01-10T14:12:57.000Z (about 2 years ago)
- Last Synced: 2024-06-20T10:07:46.579Z (7 months ago)
- Topics: cdb, golang, key-value, key-value-store
- Language: Go
- Size: 17.6 KB
- Stars: 3
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# CDB64
[![Build Status](https://travis-ci.org/bsm/cdb64.png?branch=master)](https://travis-ci.org/bsm/cdb64)
[![GoDoc](https://godoc.org/github.com/bsm/cdb64?status.png)](http://godoc.org/github.com/bsm/cdb64)
[![Go Report Card](https://goreportcard.com/badge/github.com/bsm/cdb64)](https://goreportcard.com/report/github.com/bsm/cdb64)
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)This is a native Go implementation of [cdb][1], a constant key/value database
with some very nice properties, but without the 4GB size limit.Adapted from the original [design doc][1]:
> cdb is a fast, reliable, simple package for creating and reading constant databases. Its database structure provides several features:
>
> - Fast lookups: A successful lookup in a large database normally takes just two disk accesses. An unsuccessful lookup takes only one.
> - Low overhead: A database uses 4096 bytes, plus 32 bytes per record, plus the space for keys and data.
> - No random limits: cdb can handle any database up to 16 exabytes. There are no other restrictions; records don't even have to fit into memory. Databases are stored in a machine-independent format.[1]: http://cr.yp.to/cdb.html
This repo is based on github.com/chrislusf/cdb64
## Usage
```go
package mainimport (
"fmt"
"log""github.com/bsm/cdb64"
)func main() {
w, err := cdb64.Create("/tmp/cdb64-example.cdb")
if err != nil {
log.Fatalln(err)
}
defer w.Close()// Write some key/value pairs.
_ = w.Put([]byte("Alice"), []byte("Hoax"))
_ = w.Put([]byte("Bob"), []byte("Hope"))
_ = w.Put([]byte("Charlie"), []byte("Horse"))// Freeze and re-open it for reading.
db, err := w.Freeze()
if err != nil {
log.Fatalln(err)
}
defer db.Close()// Fetch a value.
v, err := db.Get([]byte("Alice"))
if err != nil {
log.Fatalln(err)
}fmt.Print(string(v))
}
```