rocksdb
stableAn in-memory key-value store with RocksDB-style column families, prefix scans, range queries, and atomic batch writes.
use plugin rocksdb::{RocksStore.new, create_cf, put, …} Functions (16)
- RocksStore.new Create a new in-memory store
- create_cf Create a named column family
- put Write a key-value pair to a column family
- get Read a value by key from a column family
- delete Delete a key from a column family
- has Check if a key exists in a column family
- keys List all keys in a column family
- count Count entries in a column family
- prefix_scan Scan keys matching a prefix
- range_scan Scan keys in a lexicographic range
- batch_write Apply multiple put/delete ops atomically
- cf_names List all column family names
- drop_cf Remove a column family
- clear_cf Delete all entries in a column family
- flush No-op flush (validates handle)
- compact No-op compaction (validates handle)
Overview
rocksdb is an embedded key-value store modeled on RocksDB's data layout, but
kept entirely in memory. A store is created with RocksStore.new() and handed
back as a RocksStore handle that you pass implicitly through method calls.
Data lives in named column families — independent, lexicographically sorted
key spaces that let you separate concerns (users, sessions, logs) inside one
store, with a "default" family always present.
Because keys are kept in sorted order, the store shines at ordered access:
prefix_scan pulls every key sharing a prefix, range_scan walks a
[start, end) window, and batch_write applies many puts and deletes in one
call. Values are stored as raw bytes (strings are accepted and encoded for you),
and get returns bytes or nil. Reach for it when you want RocksDB-style
ergonomics — column families, ordered scans, batched mutations — without a disk
dependency, for caching, prototyping, or test fixtures.
Common patterns
Group related records under their own column family, then read them back:
use plugin rocksdb::{RocksStore}
let db = RocksStore.new()
db.create_cf("users")
db.put("users", "u:1", "Alice")
db.put("users", "u:2", "Bob")
print("user count: {db.count("users")}")
print(db.get("users", "u:1")) // Alice
Use sorted keys to model a secondary index and scan it by prefix:
use plugin rocksdb::{RocksStore}
let db = RocksStore.new()
db.put("default", "post:2026:hello", "first")
db.put("default", "post:2026:world", "second")
db.put("default", "tag:rust", "x")
let posts = db.prefix_scan("default", "post:2026:")
for entry in posts {
print("{entry["key"]} -> {entry["value"]}")
}
Apply several mutations atomically with a batch, then verify the result:
use plugin rocksdb::{RocksStore}
let db = RocksStore.new()
db.put("default", "stale", "old")
db.batch_write([
#{"op": "put", "cf": "default", "key": "a", "value": "1"},
#{"op": "put", "cf": "default", "key": "b", "value": "2"},
#{"op": "delete", "cf": "default", "key": "stale"}
])
print("entries: {db.count("default")}") // 2
print(db.has("default", "stale")) // false
Create a new in-memory store
Creates a new in-memory store with a single "default" column family pre-created.
use plugin rocksdb::{RocksStore}
let db = RocksStore.new()
db.put("default", "greeting", "hello")
print(db.get("default", "greeting")) // hello
Create a named column family
Creates a new column family with the given name. If it already exists, this is a no-op. Use column families to logically separate different data namespaces.
use plugin rocksdb::{RocksStore}
let db = RocksStore.new()
db.create_cf("users")
db.create_cf("sessions")
db.put("users", "u:1", "Alice")
db.put("sessions", "s:abc", "u:1")
Write a key-value pair to a column family
Inserts or overwrites a key in the specified column family. The value can be a string or bytes.
use plugin rocksdb::{RocksStore}
let db = RocksStore.new()
db.put("default", "config:timeout", "30")
db.put("default", "config:retries", "3")
print(db.count("default")) // 2
Read a value by key from a column family
Returns the value for the given key, or nil if the key does not exist.
use plugin rocksdb::{RocksStore}
let db = RocksStore.new()
db.put("default", "name", "Zolo")
let val = db.get("default", "name")
print(val) // Zolo
let missing = db.get("default", "nonexistent")
print(missing) // nil
Pair get with has to branch on presence before reading:
use plugin rocksdb::{RocksStore}
let db = RocksStore.new()
db.put("default", "session:abc", "u:1")
if db.has("default", "session:abc") {
print("owner: {db.get("default", "session:abc")}")
} else {
print("session expired")
}
Delete a key from a column family
Removes a key from the column family. Silently does nothing if the key does not exist.
use plugin rocksdb::{RocksStore}
let db = RocksStore.new()
db.put("default", "temp", "value")
db.delete("default", "temp")
print(db.has("default", "temp")) // false
Check if a key exists in a column family
Returns true if the key exists in the column family.
use plugin rocksdb::{RocksStore}
let db = RocksStore.new()
db.put("default", "x", "1")
print(db.has("default", "x")) // true
print(db.has("default", "y")) // false
List all keys in a column family
Returns all keys in the column family as a 1-indexed table of strings, in sorted order.
use plugin rocksdb::{RocksStore}
let db = RocksStore.new()
db.put("default", "b", "2")
db.put("default", "a", "1")
let ks = db.keys("default")
print(ks[1]) // a
print(ks[2]) // b
Count entries in a column family
Returns the number of key-value pairs in the column family.
use plugin rocksdb::{RocksStore}
let db = RocksStore.new()
db.put("default", "k1", "v1")
db.put("default", "k2", "v2")
print(db.count("default")) // 2
Scan keys matching a prefix
Returns all entries whose key starts with prefix. Each result is a table with key and value fields.
use plugin rocksdb::{RocksStore}
let db = RocksStore.new()
db.put("default", "user:1", "Alice")
db.put("default", "user:2", "Bob")
db.put("default", "post:1", "Hello")
let users = db.prefix_scan("default", "user:")
print(users[1]["key"]) // user:1
print(users[1]["value"]) // Alice
Iterate the matched entries to build a quick report:
use plugin rocksdb::{RocksStore}
let db = RocksStore.new()
db.create_cf("metrics")
db.put("metrics", "cpu:host1", "12")
db.put("metrics", "cpu:host2", "47")
db.put("metrics", "mem:host1", "80")
for row in db.prefix_scan("metrics", "cpu:") {
print("{row["key"]} = {row["value"]}")
}
Scan keys in a lexicographic range
Returns all entries with keys in [start_key, end_key). Results are ordered and each entry has key and value fields.
use plugin rocksdb::{RocksStore}
let db = RocksStore.new()
db.put("default", "2024-01", "jan")
db.put("default", "2024-03", "mar")
db.put("default", "2024-06", "jun")
let q1 = db.range_scan("default", "2024-01", "2024-04")
print(q1[1]["key"]) // 2024-01
The end_key is exclusive, so a half-open window over an ID range stops just
before its upper bound:
use plugin rocksdb::{RocksStore}
let db = RocksStore.new()
db.put("default", "id:001", "a")
db.put("default", "id:002", "b")
db.put("default", "id:003", "c")
let window = db.range_scan("default", "id:001", "id:003")
print(db.count("default")) // 3
print(window[1]["key"]) // id:001
print(window[2]["key"]) // id:002 (id:003 excluded)
Apply multiple put/delete ops atomically
Applies a list of put/delete operations atomically. Each op is a table with fields: op ("put" or "delete"), cf (column family, defaults to "default"), key, and value (for puts).
use plugin rocksdb::{RocksStore}
let db = RocksStore.new()
db.batch_write([
#{"op": "put", "cf": "default", "key": "a", "value": "1"},
#{"op": "put", "cf": "default", "key": "b", "value": "2"},
#{"op": "delete", "cf": "default", "key": "old"}
])
List all column family names
Returns a sorted list of all column family names.
use plugin rocksdb::{RocksStore}
let db = RocksStore.new()
db.create_cf("logs")
db.create_cf("cache")
let names = db.cf_names()
print(names[1]) // cache
print(names[2]) // default
print(names[3]) // logs
Remove a column family
Removes a column family and all its data. Returns true if the family existed and was dropped, false if it did not exist. The "default" column family cannot be dropped.
use plugin rocksdb::{RocksStore}
let db = RocksStore.new()
db.create_cf("temp")
print(db.drop_cf("temp")) // true
print(db.drop_cf("temp")) // false
Delete all entries in a column family
Deletes all entries in a column family without removing the family itself.
use plugin rocksdb::{RocksStore}
let db = RocksStore.new()
db.put("default", "k", "v")
db.clear_cf("default")
print(db.count("default")) // 0
No-op flush (validates handle)
No-op for the in-memory store. Validates that the handle is still valid. Mirrors the RocksDB flush API for compatibility.
No-op compaction (validates handle)
No-op for the in-memory store. Validates that the handle is still valid. Mirrors the RocksDB compact API for compatibility.