0

I'm coming from mysql, trying to wrap my head around redis. Some things were very obvious but a couple have me stumped. How would you go about implementing such things in redis?

First

I have a sort of first come/first serve reservation system. When a user goes to a specific page, it queries the table below and returns the first badge where reservedby = 0, it then updates reservedby with the users id. If the user doesn't complete the process within 15 minutes, reservedby is reset to 0. If the user completes the process, I delete the row from the table and store the badge with the user data. Order is important, the higher on the list a badge is, the better, so if I were to remove it instead of somehow marking it reserved, it would need to go back in on the top if the process isn't completed with 15 minutes.

id  | badge | reservedby
------------------------
240 | abc   | 4249
241 | bbb   | 0
242 | rrr   | 0

Second

I have a set of data that doesn't change very often but is queried a lot. When a page loads, it populates a select box with each color, when you select a color, the corresponding sm and lg are displayed.

id |  color   |  sm  |  lg
---------------------------
1  |  blue    |  1   |  5
2  |  red     |  3   |  10
3  |  yellow  |  7   |  8

Lastly

As far as storing user data, what I'm doing is INCR users and then taking that value and hmset user:<INCR users value> badge "aab" joindate "10/30/2013" etc, is that typically how it should be done?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Roger
  • 4,249
  • 10
  • 42
  • 60

1 Answers1

0

in reversed order

  • yes thats how you increment IDs in Redis, there is no automated feature.

  • depending on how frequent does the table change, if its once a month consider serving a static json file to client and let client-side deal with the rest of the code.

  • consider using a ZSET and try to keep unique values at scores, OR a LIST with json values.

IMHO your reservation system internals kind of sucks, i could easily reserve your sites offers simply , by sending multiple http requests, other production websites have a limited offer and the user who pays first has the room, until the payment is processed on success it just keeps going, on failure it reverts back.

Gntem
  • 6,949
  • 2
  • 35
  • 48