T
T
T4-1002014-01-20 16:50:03
PHP
T4-100, 2014-01-20 16:50:03

Memcached and fetching from MySql

There is a table with 10 million records. It stores some data + key1 and key2. With some action on the site, two parameters param1 and param2 come to the script. And you need to check if there is a string in the database that satisfies the condition key1=param1 and key2=param2. If not, insert these parameters into the table.
The question is:
1) will it be correct to store the whole table in Memcached? Or is it better to store the keys as $key = md5(serialize($options)), where $options describes all the query options.
2) If you store the entire table, then how to check that Memcached has a key corresponding to the condition key1=param1 and key2=param2

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Y
Yakov Akulov, 2014-01-20
@jakulov

Memcached, in principle, can be excluded from here.
In the database, it is enough to make a composite index on the fields key1 and key2 - the selection will be fast
dev.mysql.com/doc/refman/5.0/en/multiple-column-in...
if in memcached - then $key = $key1 .'_ '. $key2 - there will be a selection from memcached by parameters, and already necessary serialized data will be put into the value

V
Vit, 2014-01-20
@fornit1917

1. As a memcached key, you can use the concatenation of key1 and key2.
2. Are you sure you need memcached? Selecting by key from a 10 million table in MySQL does not take much time. If there is a composite index on key1+key2.

E
Evgeniy Golovin, 2014-01-20
@JonGol

There are more than 10M in the database (auto parts), fields key1 + key2
Everything flies fine

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question