I think two reasons
1 Mysql
and redis
both provide persistence, but why mysql
is is used more than redis
in persistence? Maybe redis
has no index and cannot be used to answer queries directly from disk. But since we can query from memory, there is no need query from disk.
2 Redis
saves data to disk on a periodic basis, then data loss may occur, but does Mysql
save data to disk immediately after insert
without time window?
CodePudding user response:
Redis and MySQL are really two very different technologies. Redis primarily serves as a cache for storing data temporarily as a key-value store. While it is true that Redis can be configured to write back to a database or file under the hood, Redis itself is neither of these things. Instead, Redis is meant to store data which generally would be considered volatile.
On the other hand, MySQL is a database and a full blown data store. MySQL is suitable for permanently storing data, and also exposes a rich API for making it easy to query and search its data.
In terms of common ground, a query against a MySQL column which has a hash index would behave somewhat similarly to a lookup in a Redis cache, each using a certain key. But the difference is that, in general, Redis will perform about 100 times faster than a database. For this reason, when a lightning fast cache technology is needed, MySQL often will not be suitable for this purpose, but a cache like Redis might be suitable.