Redis user management system

I am converting my old MySQL based user management system to Redis and am facing several issues ...

I use a combination of HASH and SET as the basis of the system.

Just some pseudocode

let uid=incr user_id_counter

    hset joe@dom.com user user:uid
    hset user:uid email joe#dom.com
    hset user:uid gender m
    hset user:uid year_of_birth 1972
    hset user:uid fav_band acdc
    sadd maleUsers uid
    sadd born1972Users uid

      

at this point everything is fine and I can search using an agglomerate like:

sinter maleUsers born1972
or
sinter femaleUsers born1980

      

This assumes that I make a separate set for each year birh

sad bornXXXX uid

      

I can get it in my stomach, but how would I cope with my favorite band? Surely, I wouldn't make a set for all possible groups?

Eventually I would like to be able to do detailed searches like

sinter maleUsers born1980 genreRock genreMetal homeTownSydney

      

Is there a more complex way to do relational queries?

+3


source to share


2 answers


I'm a big fan or Redis. But I'm afraid your approach is completely wrong. Your main store for user credentials should still be a traditional RDBMS, and sticking with MySQL is a great way to do it.

NoSQL databases, and in particular Redis, are for different purposes.



Redis is memory based. Yes, you can save everything to your hard drive, but when you boot the machine, it will load everything from your hard drive into memory. And - your memory is the memory of your computer. Therefore, unless you are counting on too many users, I would not recommend Redis as your primary storage source. You can use Redis to provide additional access to your users (like a second-level cache), but not as a primary source.

You can use disk-based NoSQL databases (MongoDB, CouchDB, Cassandra and all those) for your user database, which is a better choice than Redis, but I still highly recommend using traditional RDBMS for this. You want to store your most important data in a secure transaction-based system.

+3


source


But how would I work with a fav group? Surely, I wouldn't make a set for all possible groups?

Well, that's exactly what you should be doing. With Redis, this relationship is represented by a lane link, part of the user definition, and a set associated with a lane containing links to all users.

This link must be stored manually, but you can use MULTI / EXEC blocks to ensure data consistency in a parallel environment.



Is there a more complex way to do relational queries?

Yes, using a relational database instead of Redis. If you're looking for relational queries, why not use a DBMS? What's wrong with MySQL?

0


source







All Articles