← All libraries

SugarSkate

SugarSkate

In-memory key/value store with multiple backends

port of charmbracelet/skate storekey-valuecachedatabase

In-memory key/value store with a plugin architecture. Ships with Memory, SQLite, Badger (BadgerDB), and InMemory backends. Supports glob + prefix listing.

Install

composer require sugarcraft/sugar-skate

Quickstart

use SugarCraft\Skate\{Database, Store};

$db = new Database(new \SugarCraft\Skate\Backend\MemoryStore());
$store = $db->store('my-app');

$store->set('user:1', 'Alice', ['role' => 'admin']);
echo $store->get('user:1'); // 'Alice'

foreach ($store->list('user:*') as $key => $value) {
    echo "$key => $value\n";
}

What's in the box

Multiple backendsMemory, SQLite, Badger (BadgerDB via exec), InMemory.
Glob listingPattern-based key listing with prefix support.
TTL supportExpire keys after a set time.
Batch opsPut many keys at once for efficiency.

Source & demos

Try the quickstart →

API

ClassMethodDescription
Databasenew(backend)Create database with backend
Databasestore(name)Get named store
Storeset(key, value, meta)Set a key-value pair
Storeget(key)Get value by key
Storedelete(key)Delete a key
Storelist(pattern)List keys matching pattern
MemoryStorenew()In-memory backend
SqliteStorenew(path)SQLite backend

Demos.

VHS-recorded GIFs of every example shipped with the library. Regenerated automatically on every push that touches the source.

Get / set / list

Get / set / list

Default in-memory store — set, get, list, delete.
Glob listing

Glob listing

List keys matching `users/*` and `cache/*`.
Reverse-order list

Reverse-order list

List a key range in reverse insertion order.
Binary values

Binary values

Round-trip raw bytes in / out of the store.
Multiple DBs

Multiple DBs

Two named stores side-by-side, no collisions.