4

I have been playing around with Nodejs and now wanted to know if i could create live update to a view/page as shown in this tutorial here

The example above would apply to all users on site, what i want is to target my updates to certain users.

Do i create a array storing all the client sockets, a socket is created when the users logs in.

Another thing how can i update the webpage or the view if something has updated in the database do i poll the server every second?

I am using MySQL has database, should i used Redis instead?

EDIT: one more question I was wondering how can nodejs check if the database field/s have been updated or changed and than update the view or webpage?

thanks

1 Answer 1

1

Do i create a array storing all the client sockets, a socket is created when the users logs in.

If you would use socket.io module for managing connection between clients and server, then you don't have to worry about the structure or stored clients since it would be managed for you in the background. It offers also various fallbacks (including long polling) if client browsers do not support advanced transports like WebSockets.

Another thing how can i update the webpage or the view if something has updated in the database do i poll the server every second?

DO NOT poll the server every second, since transports like long polling and WebSockets were introduced to AVOID this. Since you would have persistent connection between client and server with socket.io (which are using techniques and technologies like long polling or WebSockets), you can rather easily create evented system which updates or notifies certain client(s) about the change at the time when it happens.

I am using MySQL has database, should i used Redis instead?

Redis is very good Key/Value store for real-time, frequently updated data which do not require complex querying. If you need advanced querying support for your data, then try to look at MongoDB for example.

Sign up to request clarification or add additional context in comments.

1 Comment

I think he was referring to polling the database every second with that second quote. (Which is also a bad idea). I think this is what he was looking for, assuming he's not using an ORM that provides similar event hooks: dev.mysql.com/doc/refman/5.0/en/triggers.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.