https://github.com/maxtek6/keybase-go
Key counting database with expiring keys and optional persistence.
https://github.com/maxtek6/keybase-go
dracula mailsac sqlite sqlite-database sqlite3
Last synced: 10 months ago
JSON representation
Key counting database with expiring keys and optional persistence.
- Host: GitHub
- URL: https://github.com/maxtek6/keybase-go
- Owner: maxtek6
- License: mit
- Created: 2024-06-25T22:45:28.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2025-02-27T06:05:58.000Z (over 1 year ago)
- Last Synced: 2025-05-17T11:11:19.811Z (about 1 year ago)
- Topics: dracula, mailsac, sqlite, sqlite-database, sqlite3
- Language: Go
- Homepage:
- Size: 62.5 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Keybase
[](http://pkg.go.dev/github.com/maxtek6/keybase-go)
[](https://codecov.io/gh/maxtek6/keybase-go)
[](https://goreportcard.com/report/github.com/maxtek6/keybase-go)
Keybase is a key counting database with expiring keys and optional persistence.
## Usage
Keybase is designed to work out of the box with minimal configuration. To use keybase,
call the `Open()` function:
```go
kb, err := keybase.Open(keybase.WithStorage("/tmp/keybase.db"), keybase.WithTTL(time.Minute))
```
This will initialize a database at `/tmp/keybase.db` with a key timeout of one minute. Once
keybase is open, it is ready to store and maintain keys. Each key is assigned to a namespace
and can be inserted using the `Put` function:
```go
_ = kb.Put(context.Background(), "namespace", "key")
```
Once the key is stored, various functions can be used to query key and namespace information,
such as `GetKeys()`, which will return a slice of strings representing all keys in a given
namespace:
```go
active := true
unique := true
keys, err := kb.GetKeys(context.Background(), "namespace", active, unique)
```
By setting `active` and `unique` to `true`, the slice will include each active key once. Otherwise,
the string make contain multiple copies of the same key, as well as stale keys, if it has been
submitted multiple times and queried within the TTL duration. Over time, as the keys become stale,
they can be removed using the `PruneEntries` function:
```go
_ = kb.PruneEntries(context.Background())
```
This will remove the stale keys and reduce the amount of storage required by memory or
filesystem. When the keybase is no longer needed, it needs to be disconnected using the
`Close()` function:
```go
kb.Close()
```