@tigrisdata/keyv-tigris
v1.0.7
Published
Keyv storage adapter for Tigris
Downloads
828
Readme
Tigris Adapter for Keyv
A Tigris Storage adapter for Keyv.
Why use object storage as a key–value store? Tigris excels at handling small objects. Here’s a detailed write-up and benchmark: Benchmarking Small Objects
Installation
npm install @tigrisdata/keyv-tigris keyvConfiguration
Create an account and set up bucket at storage.new
Set up your Tigris credentials using environment variables (you can also use .env file).
TIGRIS_STORAGE_BUCKET=your-bucket-name
TIGRIS_STORAGE_ACCESS_KEY_ID=your-access-key
TIGRIS_STORAGE_SECRET_ACCESS_KEY=your-secret-key
TIGRIS_STORAGE_ENDPOINT=https://t3.storage.dev # optional, defaults to thisimport Keyv from 'keyv';
import { KeyvTigris } from '@tigrisdata/keyv-tigris';
const store = new KeyvTigris();
// Or pass the configuration directly:
const store = new KeyvTigris({
bucket: 'your-bucket-name',
accessKeyId: 'your-access-key',
secretAccessKey: 'your-secret-key',
endpoint: 'https://t3.storage.dev',
});
const keyv = new Keyv({ store });Usage
Basic Operations
import Keyv from 'keyv';
import { KeyvTigris } from '@tigrisdata/keyv-tigris';
const keyv = new Keyv({ store: new KeyvTigris() });
// Set a value
await keyv.set('foo', 'bar');
// Get a value
const value = await keyv.get('foo'); // 'bar'
// Delete a key
await keyv.delete('foo');
// Clear all keys
await keyv.clear();
// Check if key exists
await keyv.has('foo'); // falseUsing Namespaces
Namespaces allow you to isolate different sets of keys (handled by Keyv):
const users = new Keyv({
store: new KeyvTigris(),
namespace: 'users',
});
const sessions = new Keyv({
store: new KeyvTigris(),
namespace: 'sessions',
});
// These don't conflict
await users.set('123', { name: 'Alice' });
await sessions.set('123', { token: 'abc' });Iterating Over Keys
const keyv = new Keyv({ store: new KeyvTigris() });
await keyv.set('key1', 'value1');
await keyv.set('key2', 'value2');
for await (const [key, value] of keyv.iterator()) {
console.log(key, value);
}Batch Operations
// Get multiple values
const values = await keyv.get(['key1', 'key2', 'key3']);
// Delete multiple keys
await keyv.delete(['key1', 'key2']);Error Handling
const store = new KeyvTigris();
store.on('error', (error) => {
console.error('Storage error:', error);
});
const keyv = new Keyv({ store });API
Constructor Options (TigrisStorageCoreConfig)
| Option | Type | Description |
| ----------------- | -------- | ------------------------------------------------------- |
| bucket | string | Tigris bucket name |
| accessKeyId | string | Tigris access key ID |
| secretAccessKey | string | Tigris secret access key |
| endpoint | string | Tigris endpoint URL (default: https://t3.storage.dev) |
License
MIT
