Is it worth using Redis over just storing data in objects that are only needed during runtime?

315
January 07, 2017, at 2:37 PM

I'm creating a party system for a thing I'm working on,

using sockets the person can emit an accept, decline, invite, kick, changeLeader events for the party.

I needed some way to keep track of the users so I created an object that would contain all relevant information, e.g.

let partyManager = {};
partyManager[partyUUID] = {
    creator: username,
    creatorSID: g04wn0gn9w490g, // socket id
    members: [],
    invited: []
}

but I thought well maybe its hard on the program to store this information in the program itself and maybe a database is more suitable for this, but I wanted something fast and to be honest, just really wanted to try out Redis..

So I started working on my store / schema for redis to store the information I came up with something like

hmset party:uuid:owner   "creator" "username" "creatorSID" "socket id"
sadd  party:uuid:members "user1" "user2"
sadd  party:uuid:invited "user3"

Which gives me a hash containing the party owners information and 2 sets pertaining to the current members, and the users with pending invites (so people cant just join a party they haven't been invited to)

But then I remembered Redis stores in memory anyways, which storing in an object would store in memory as well, would it not?

I'm mainly wondering if using Redis to accomplish this is more effective/better than just storing the party in an object.

Answer 1

According to me, the main interests of using Redis in your case would be:

  • to make data persistent, if Redis persistance is activated
  • to allow sharing the data between several instances of the application server
  • to make this application server stateless (which is better for failover and scaling).

If you don't bother with these considerations, Redis has a low interest in the use case you described.

Rent Charter Buses Company
READ ALSO
Node Child Process Spawn “TypeError: Bad argument TypeError”?

Node Child Process Spawn “TypeError: Bad argument TypeError”?

When I run the following code with node:

484
Is there an implementation of ReadableStream class in node js?

Is there an implementation of ReadableStream class in node js?

I need an implementation of ReadableStream class in node js, same as: mdn ReadableStreamI know that node supports stream

358
error in demo script with createReadStream

error in demo script with createReadStream

Why do I get this error in nodejs? The idea is to write something just after the bunch is completely read in order to avoid that putting data in earlier than reading the content of the file

402
ran npm install on github but cant import the javascript files

ran npm install on github but cant import the javascript files

I successfully ran npm install on a project named 'react-slingshot-Boilerplate' from githubIn the node_modules folder, I can see the project 'react-slingshot-Boilerplate' after running npm install

441