Answers for "how to implement redis pub sub model using nodejs"

1

how to implement redis pub sub model using nodejs

var redis = require(“redis”);var publisher = redis.createClient();publisher.publish(“notification”, “{\”message\”:\”Hello world from Asgardian!\”}”, function(){ process.exit(0);});
Posted by: Guest on February-04-2021
0

redis pub or sub nodejs

more example redis pub/sub -> https://github.com/restuwahyu13/express-todo-redis
Posted by: Guest on February-24-2021
0

how to implement redis pub sub model using nodejs

var redis = require(“redis”);var subscriber = redis.createClient();subscriber.on(“message”, function (channel, message) { console.log(“Message: “ + message + “ on channel: “ + channel + “ is arrive!”);});subscriber.subscribe(“notification”);
Posted by: Guest on February-04-2021
0

redis pub or sub nodejs

// publisher

const IORedis = require('ioredis')

class Publisher {
	constructor(configs = { key: '' }) {
		this.key = configs.key
		Publisher.set(configs.key)
	}

	static get() {
		return this.key
	}

	static set(key = '') {
		this.key = key
	}

	_redisConnect() {
		const ioRedis = new IORedis({
			host: '127.0.0.1',
			port: 6379,
			maxRetriesPerRequest: 50,
			connectTimeout: 5000,
			enableReadyCheck: true,
			enableAutoPipelining: true
		})

		return ioRedis
	}

	async setString(keyName = '', data) {
		const ioRedis = _redisConnect()
		await ioRedis.set(keyName, data)
	}

	async setMap(keyName = '', data = {}) {
		const ioRedis = this._redisConnect()
		await ioRedis.hmset(keyName, { ...data })
	}

	async setArray(keyName = '', data = []) {
		const ioRedis = _redisConnect()
		await ioRedis.hmset(keyName, JSON.stringify({ data: data }))
	}

	async setResponse(data = {}) {
		const ioRedis = this._redisConnect()
		await ioRedis.hmset('message:speaker', { ...data })
	}
}

module.exports = { Publisher }
Posted by: Guest on February-24-2021

Code answers related to "how to implement redis pub sub model using nodejs"

Code answers related to "Javascript"

Browse Popular Code Answers by Language