mysql - Node.js redis pubsub -


i'm beginner of nodejs. want make chatting service using nodejs. use nodejs/jade/mysql construct basic part of system , want provide pub/sub users.

we receive users' interests text field or using hash tags (anyway received users' interests , stored in mysql -> did it). then, want show users chatting room list according interests. instance a's interests 'game', 'car' , 'food', search chat rooms 'game', 'car', 'food' , show these chat rooms first.

i want use redis provide service have no idea!

1) installed redis , can run redis-server.
2)

//redis  var redis = require('redis');  var publisher = redis.createclient();  var subscriber = redis.createclient();    subscriber.on('message', function(channel, message){    console.log('message ' + message + ' on channel ' + channel + ' arrived!');  });    subscriber.on('subscribe', function(channel){    publisher.publish('test', 'the team');    publisher.publish('test', 'the b team');    })    subscriber.subscribe('test');

this short code tried understand redis.

3) don't know how can read data stored in mysql , show users chat room according interests using redis.

redis advanced key-value cache , store.its operations cannot directly mapped mysql.

in redis can set either key value pair or hash under key. : if want store name in redis can done by:

var client = redis.createclient();  client.set("name", "john")   

retrieve values using client.get("name")

similarly under single key can store multiple key value pairs, hash. under name if want store details age, place, company etc.then hash should used. redis has method "hmset" , "hmget" hash opertaions.

in redis in cache can set expiry time.

there different method available. can explore those. reference http://redis.io/commands


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -