Dashboard

Key-Value Storage

Store and retrieve key-value pairs organized into namespaces. Useful for caching, configuration, and persisting small pieces of scraped data.

Creating a Namespace

import { ScrayleClient } from '@scrayle/sdk';

const client = new ScrayleClient();

const ns = await client.storage.kv.createNamespace('my-cache');
console.log(ns.id); // Namespace ID

Setting Values

// Set a single value
await client.storage.kv.setValue(ns.id, {
  key: 'user:123',
  value: JSON.stringify({ name: 'John', email: '[email protected]' }),
  expiration: 3600, // Optional TTL in seconds
});

// Bulk set multiple values
await client.storage.kv.bulkSetValue(ns.id, [
  { key: 'key1', value: 'value1' },
  { key: 'key2', value: 'value2' },
  { key: 'key3', value: 'value3', expiration: 7200 },
]);

Getting Values

const value = await client.storage.kv.getValue(ns.id, 'user:123');
const data = JSON.parse(value);
console.log(data.name); // 'John'

Listing Keys

const keys = await client.storage.kv.listKeys(ns.id, {
  page: 1,
  pageSize: 50,
});

for (const item of keys.items) {
  console.log(item.key, item.size);
}

Deleting Values

// Delete a single value
await client.storage.kv.delValue(ns.id, 'user:123');

// Bulk delete
await client.storage.kv.bulkDelValue(ns.id, ['key1', 'key2']);

Managing Namespaces

// List all namespaces
const namespaces = await client.storage.kv.listNamespaces({
  page: 1, pageSize: 20,
});

// Get namespace details
const ns = await client.storage.kv.getNamespace('ns-id');

// Rename a namespace
await client.storage.kv.renameNamespace('ns-id', 'new-name');

// Delete a namespace (and all its data)
await client.storage.kv.delNamespace('ns-id');

API Reference

MethodDescription
kv.createNamespace(name)Create a new namespace
kv.getNamespace(id)Get namespace details
kv.listNamespaces(params)List all namespaces
kv.renameNamespace(id, name)Rename a namespace
kv.delNamespace(id)Delete a namespace
kv.setValue(nsId, data)Set a single key-value pair
kv.getValue(nsId, key)Get a value by key
kv.bulkSetValue(nsId, data[])Set multiple values at once
kv.delValue(nsId, key)Delete a value
kv.bulkDelValue(nsId, keys[])Delete multiple values
kv.listKeys(nsId, params)List keys in a namespace