Giter VIP home page Giter VIP logo

revent's Introduction

Revent

###Redis pub/sub module for NodeJS

Install

npm i reventjs --save

Config

{
host: /* Redis host */,
port: /* Redis port */,
db:   /* Redis DB connect */,
options: {/* Redis options */},
createClient: /* Redis client instance */,
messagePattern: /* Message pattern RexExp*/
}

Usage

Subscribe

import Revent  from 'reventjs';
const redis = Revent.create({/* config */});

redis
.on('ready', () => {

	redis.on('hello:*', ['expired','del' ,(data, channel, pattern) => {
		console.log(data, channel, pattern);
	}]);

})
.on('error', (err) => {
  console.error(`Redis client error: ${err}`);
});

// OR
redis
.on('ready', () => {
  console.log('Redis ready');
})
.on('error', (err) => {
  console.error(`Redis client error: ${err}`);
});

redis.on('hello:*', ['expired','del' ,(data, channel, pattern) => {
  console.log(data, channel, pattern);
}]);

Unsubscribe

// space - Keyspace
redis.off('hello:* world:*',[() => {
  console.log('unsubscribe hello:*');
}]);

// event - Keyevent
redis.off('events',[() => {
  console.log('unsubscribe Events');
}]);

Publish

redis.send('hello:*', {name:'Peter'});

Connection close

redis.close();

//Hard
redis.end();

Redis command

redis.command().expire(`hello:123`, 0, (err, reply) => {
	if(err || !reply) {
		console.error(err);
	}
});

Important

Do not forget to set up Redis and add to redis.conf line:

--notify-keyspace-events <options>

  • K Keyspace events, published with keyspace@ prefix.
  • E Keyevent events, published with keyevent@ prefix.
  • g Generic commands (non-type specific) like DEL, EXPIRE, RENAME, ...
  • $ String commands
  • l List commands
  • s Set commands
  • h Hash commands
  • z Sorted set commands
  • x Expired events (events generated every time a key expires)
  • e Evicted events (events generated when a key is evicted for maxmemory)
  • A Alias for g$lshzxe, so that the "AKE" string means all the events.

It is also possible to use the. view

Dear friends, if you find any bugs or you will have suggestions, I'll tell you thanks very much. And you plus one in karma;)

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.