I've been considering using Redis in a project that uses a lot of writes.
So, after setting it up on my server, I created a simple PHP script using Predis with a simple loop to add records. I also created a second script that does a similar thing, only on a MySQL table (InnoDB) using PHP's MySQLi.
I ran a 10k loop, a 100k loop and a 500k loop and MySQL beat Redis every single time. In fact, the more records I added, the faster MySQL was compared to Redis.
There's so much buzz (hype?) around Redis, that I want to believe I'm missing something here.
Please educate me :)
Thanks!
Here's my Predis code:
for ($i=0; $i<100000; $i++) {
$predis->set('key'.$i, $i);
}
Here's my MySQLi code:
for ($i=0; $i<100000; $i++) {
mysqli_query($db, "INSERT INTO test (`key`, `value`) VALUES ('key$i', $i)");
}
In terms of the efficiency of updating databases, Redis is superior to MySQL while SQLite is slowest. However, in terms of the efficiency of querying from databases, SQLite seems to be about ten times faster than Redis and MySQL.
While MySQL supports the XML data format, Redis does not. When concerning indexes, both allow them. However, MySQL supports secondary indexes without any restrictions while Redis only supports secondary indexes with the RediSearch module.
Redis is an open-source and in-memory data structure store that can be used for caching, real-time analytics, searching, and machine learning. Integrate Redis with PHP and MySQL will improve your application performance because Redis stores data in RAM. You can use it with databases like MySQL or MariaDB.
Replication and persistenceRedis employs a primary-replica architecture and supports asynchronous replication where data can be replicated to multiple replica servers. This provides improved read performance (as requests can be split among the servers) and faster recovery when the primary server experiences an outage.
the mysqli extension - is an extension whereas predis is a php-client library. I.e. whereas mysqli is compiled code, predis is just plain php - extensions are faster.
A benchmark of the kind shown in the question primarily shows the performance loss of PHP code versus an extension.
If you want to make a comparison of write performance - you'll need to compare to the php redis extension.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With