Unleash awesomeness. Private packages, team management tools, and powerful integrations. Get started with npm Orgs »

redis-stream-access

1.2.0 • Public • Published

redis-stream-access

Write and read stream values from Redis database

Installation

Install redis-stream-access from npm. You also need redisup to be installed.

npm install redis-stream-access redis

Setup

Create a redis-stream-access instance by providing a Redis config object that is used for storage.

const redisStreamAccess = require('redis-stream-access');
const redisStream = redisStreamAccess({host: 'localhost', port: 6379});

createWriteStream()

Write a large stream into redisdb database

let writer = redisStream.createWriteStream('keyname');

Example

fs.createReadStream('file.txt').
    pipe(redisStream.createWriteStream('keyname'));

createReadStream()

Read a stream from redisdb database

let reader = redisStream.createReadStream('keyname');

Example

redisStream.createReadStream('keyname').
    pipe(process.stdout);

setMeta()

Attach JSON metadata to the stored stream. This value gets removed when you delete the stream. If there already was metadata set, it gets overwritten. If the stream does not exists, then metadata is not stored and callback returns false, otherwise it returns true

redisStream.setMeta(keyname, data, callback);

Where

  • keyname is the stream key to add metadata to
  • data is an object that can be converted to JSON
  • callback is the function to run once data is stored

Example

redisStream.setMeta('keyname', {
    filename: 'some-file.txt'
}, function(err, stored){
    if(err){
        console.log(err);
    }else if(!stored){
        console.log('Stream was not found');
    }else{
        console.log('metadata was stored');
    }
});

getMeta()

Get JSON metadata for the stored stream. This value combines both the user defined metadata using setMeta and system metadata (eg. created with creation timestamp).

redisStream.getMeta(keyname, callback);

Where

  • keyname is the stream key to get metadata for
  • callback is the function to run once data is stored

Example

redisStream.setMeta('keyname', function(err, meta){
    if(err){
        console.log(err);
    }
    if(!meta){
        console.log('Stream was not found!');
    }else{
        // user defined metadata
        console.log(meta.filename); // 'some-file.txt'
        // system provided metadata
        console.log(meta.created); // 1470901349281
    }
});

delete()

Delete streamed data from redisdb

redisStream.delete('keyname', callback);

Example

redisStream.delete('keyname', function(err, deleted){
    if(err){
        console.log(err);
    }else{
        console.log('%s chunks deleted', deleted);
    }
});

License

MIT

Keywords

install

npm i redis-stream-access

Downloadsweekly downloads

1

version

1.2.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability