Socket
Book a DemoInstallSign in
Socket

@etomon/ioredisdown

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@etomon/ioredisdown

Redis backend for level which uses ioredis as the redis client

latest
Source
npmnpm
Version
1.2.3
Version published
Maintainers
2
Created
Source

IO Redis Down

This repository is a very simple implementation of abstract-leveldown using ioredis (redis) as the data store.

I couldn't get redis-down to function properly and figured the abstract-leveldown API was simple enough to re-implement.

Usage

  const { IORedisDown } = require('@etomon/ioredisdown');
  const Redis = require('ioredis');
  const levelup = require('levelup');
  
  //  A connection string
  let db = levelup(new IORedisDown('blah'), 'redis://localhost:6379');
  
  // As an object containing settings
  db = levelup(new IORedisDown('blah'), {
    host: '127.0.0.1',
    port: 6379
  });
  
  // Pass your own redis
  const redis = new Redis(6379, '127.0.0.1');
  
  db = levelup(new IORedisDown('blah'), {
    redis: redis
  });

Options

The options (second) parameter in levelup gets passed directly to the constructor of IORedis.

If an array is passed it will spread the array elements across the constructor.

So db = levelup(new IORedisDown('blah'), [ 6379, '127.0.0.1' ])

and

  const redis = new Redis(6379, '127.0.0.1');
  
  db = levelup(new IORedisDown('blah'), {
    redis: redis
  });

Are equivalent

Encoding

I didn't have time to figure out how encoding-down works so encoding/decoding is currently handled by `@etomon/encode-tools.

Crucially, data will be serialized as msgpack by default. Keys will be serialized as JSON, then hashed using xxhash3.

The second argument of the IORedisDown constructor can be used to configure the EncodeTools instance.

At present, the hashing algorithm must be xxhash3.

By default, these are the settings

const DEFAULT_ENCODING_OPTIONS: EncodingOptions = {
  // If Buffers need to be encoded as string they will be encoded as base64
  binaryEncoding: BinaryEncoding.base64,
  // * This is ignored, must be xxhash3 *
  hashAlgorithm: HashAlgorithm.xxhash3,
  // By default will store data as msgpack
  serializationFormat: SerializationFormat.msgpack,
  // Not used
  uniqueIdFormat: IDFormat.uuidv4String
}

Building

@etomon/ioredisdown is written in TypeScript, to build run npm run build.

Documentation

Documentation can be found here.

License

Etomon IORedisDown is licensed under the GNU LGPL-3.0, a copy of which can be found at https://www.gnu.org/licenses/.

FAQs

Package last updated on 22 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts