Coder Social home page Coder Social logo

redis-level's Introduction

redis-level

Requirements:

  • redis-2.8 or more recent.
  • node-12.x

Uses a sorted-set to order the keys and a hash to store the values.

Fetches the ordered key value pairs during iterations with a single redis lua call.

level badge Node version Standard Common Changelog

Usage

const { RedisLevel } = require('redis-level')

// Create a database
const db = new RedisLevel('tokens', { valueEncoding: 'buffer' })

// Add an entry with key 'a' and value 1
await db.put('a', 1)

// Add multiple entries
await db.batch([{ type: 'put', key: 'b', value: 2 }])

// Get value of key 'a': 1
const value = await db.get('a')

// Iterate entries with keys that are greater than 'a'
for await (const [key, value] of db.iterator({ gt: 'a' })) {
  console.log(value) // 2
}

With callbacks:

db.put('example', { hello: 'world' }, (err) => {
  if (err) throw err

  db.get('example', (err, value) => {
    if (err) throw err
    console.log(value) // { hello: 'world' }
  })
})

API

The API of redis-level follows that of abstract-level with a few additional options and methods specific to Redis. The documentation below covers it all except for Encodings, Events and Errors which are exclusively documented in abstract-level.

An abstract-level and thus redis-level database is at its core a key-value database. A key-value pair is referred to as an entry here and typically returned as an array, comparable to Object.entries().

db = new RedisLevel(location[, options])

Returns a new RedisLevel instance. location is a String pointing at the root namespace of the data in redis.

  • location+':h' is the hash where the values are stored.
  • location+':z' is the set where the keys are sorted.

Aside from the basic abstract-level options, the optional options object may contain:

  • connection represents the connection parameters, and can be one of the following :
    • an already configured redis client. RedisLevel will not open or close it.
    • a string representing a redis URL
    • options as specified by ioredis
  • highWaterMark number of values to fetch in one redis call for iteration. Defaults to 256.
  • clearOnOpen clears the database on open. Defaults to false.

The createIfMissing option of abstract-level is ignored, as this is the way that redis works.

Install

With npm do:

npm install redis-level

Credits

Based on redisDown, copyright HMalphettes.

Contributing

Level/redis-level is an OPEN Open Source Project. This means that:

Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.

See the Contribution Guide for more details.

License

MIT

redis-level's People

Contributors

ccollie 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.