V
V
vanilich2015-09-27 20:29:10
PHP
vanilich, 2015-09-27 20:29:10

Key/value values. How to choose the best storage method?

Good day.
I'm developing a Web application (I'll skip the details) where I needed to hide real user IDs (Primary Key in MySQL) behind a fixed length string (hash). Hashes are randomly generated during registration and entered into the users_hashes table like this :
| unique_hash | user_id |
Example where I will use this:
Let's say user1 sends a message to user2 via ajax to the server. The request looks like this:

{
  "from": "c1fedb2d17ca40af1c27252646d8be48",
  "to": "7f5215959290e8ec6626e904d9e84648",
  "message": "some message..."
}

The message arrives at the server, where I have to find the same hash in the " users_hashes " table and pull out the corresponding user ID, only then putting the message into the database. I understand that each such selection (although not a lot), but will load the server.
In short, I need the user not to find out about his ID (I can’t disclose the details of the project, unfortunately). And to make this whole process as efficient and fast as possible.
The first thought that came to mind is to cache the obtained values ​​from users_hashes in Memcache, and just pull out the user ID by hash.
I would appreciate any response and constructive criticism.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
IvanSenishin, 2015-09-27
@IvanSenishin

You can also use redis

R
Ruslan Fedoseev, 2015-09-27
@martin74ua

well, store it in memcache. Only .... And what is the fundamental difference between "my id 6644" and "my id c1fedb2d17ca40af1c27252646d8be48"?

N
Night, 2015-09-27
@maxtm

How much data/requests are we talking about?
If you have a database of less than 250-300k users, I think there is not much difference where to store it - in memcache, or in mysql, in terms of speed and load.
In my opinion, if this is not currently a bottleneck, then this is premature optimization.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question