Giter Site home page Giter Site logo

redilocal's Introduction

RediLocal - Redis-Like Database using Hyperbee

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.

Installation

  1. Install RediLocal package from npm:

    npm install redilocal
  2. Import RediLocal class into your Node.js application:

    const RediLocal = require('redilocal');

Usage

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);

set(key, value)

Sets a value for the given key.

await redisLikeDB.set('key1', JSON.stringify({ name: 'Alice', age: 30 }));

get(key)

Retrieves the value for the given key.

const result = await redisLikeDB.get('key1');
console.log(result); // Output: { status: true, val: { name: 'Alice', age: 30 } }

del(key)

Deletes the value for the given key.

await redisLikeDB.del('key1');

batch(commands)

Executes batch operations for setting and deleting keys.

await redisLikeDB.batch([
  { type: 'put', key: 'batchkey1', value: JSON.stringify({ item: 'value1' }) },
  { type: 'del', key: 'batchkey2' }
]);

keys(pattern = '*')

Retrieves all keys matching the optional pattern.

const allKeys = await redisLikeDB.keys('key*');
console.log(allKeys); // Output: ['key1', 'key2']

flushall()

Flushes all entries from the database.

await redisLikeDB.flushall();

readAllEntry()

Retrieves all entries from the database.

const allEntries = await redisLikeDB.readAllEntry();
console.log(allEntries);

getLimitedEntry(reverse = true, limit = 10)

Retrieves a limited number of entries from the history stream.

const limitedEntries = await redisLikeDB.getLimitedEntry(false, 1);
console.log(limitedEntries);

searchEntry(gte, limit = 10)

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.

redilocal's People

Contributors

abhijitgayen avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.