redis-level
v0.0.5
Published
Redis backed abstract-level database for Node.js
Downloads
6
Maintainers
Readme
redis-level
An abstract-level
database backed by Redis.
:pushpin: What is
abstract-level
? Head over to the FAQ.
Usage
const { RedisLevel } = require('redis-level')
// Create a database
const db = new RedisLevel({
redis: {
url: "redis://localhost:6379"
}
})
// 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
}
All asynchronous methods also support 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' }
})
})