RediLocal is a simple local database (for node.js) implementation inspired by Redis, using Hyperbee for storage. It provides basic key-value operations and supports batch operations, key listing, entry flushing, and more.
-
Install
RediLocal
package from npm:npm install redilocal
-
Import
RediLocal
class into your Node.js application:const RediLocal = require('redilocal');
Initialize a new instance of RediLocal
:
const RediLocal = require('redilocal');
const redisLikeDB = new RediLocal();
If you want to use RAM for good performance. You can use like that.
const RediLocal = require('redilocal');
const redisLikeDB = new RediLocal(true);
Sets a value for the given key.
await redisLikeDB.set('key1', JSON.stringify({ name: 'Alice', age: 30 }));
Retrieves the value for the given key.
const result = await redisLikeDB.get('key1');
console.log(result); // Output: { status: true, val: { name: 'Alice', age: 30 } }
Deletes the value for the given key.
await redisLikeDB.del('key1');
Executes batch operations for setting and deleting keys.
await redisLikeDB.batch([
{ type: 'put', key: 'batchkey1', value: JSON.stringify({ item: 'value1' }) },
{ type: 'del', key: 'batchkey2' }
]);
Retrieves all keys matching the optional pattern.
const allKeys = await redisLikeDB.keys('key*');
console.log(allKeys); // Output: ['key1', 'key2']
Flushes all entries from the database.
await redisLikeDB.flushall();
Retrieves all entries from the database.
const allEntries = await redisLikeDB.readAllEntry();
console.log(allEntries);
Retrieves a limited number of entries from the history stream.
const limitedEntries = await redisLikeDB.getLimitedEntry(false, 1);
console.log(limitedEntries);
Searches for entries within a specified range (gte
to limit
).
const searchResults = await redisLikeDB.searchEntry('entry', 10);
console.log(searchResults);
Noted : All credit goes to the Holepunch teams.