https://github.com/bsm/cdb64
cdb golang key-value key-value-store
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/bsm/cdb64
- Owner: bsm
- License: mit
- Created: 2019-06-30T11:13:38.000Z (almost 7 years ago)
- Default Branch: main
- Last Pushed: 2023-01-10T14:12:57.000Z (over 3 years ago)
- Last Synced: 2025-03-22T19:02:32.143Z (about 1 year ago)
- Topics: cdb, golang, key-value, key-value-store
- Language: Go
- Size: 17.6 KB
- Stars: 3
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# CDB64
[](https://travis-ci.org/bsm/cdb64)
[](http://godoc.org/github.com/bsm/cdb64)
[](https://goreportcard.com/report/github.com/bsm/cdb64)
[](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 main
import (
"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))
}
```