When to use Redis instead of MySQL for PHP applications?

前端 未结 6 744
-上瘾入骨i
-上瘾入骨i 2021-01-31 01:06

I\'ve been looking at Redis. It looks very interesting. But from a practical perspective, in what cases would it be better to use Redis over MySQL?

6条回答
  •  一个人的身影
    2021-01-31 01:42

    I am no Redis expert, but from what I've gathered, both are pretty different. Redis :

    • Is not a relational database (no fancy data organisation)
    • Stores everything in memory (faster, less space, probably less safe in case of a crash)
    • Is less widely deployed on various webhosts (if you're not hosting yourself)

    I think you might want to use Redis for when you have a small-ish quantity of data that doesn't need the relational structure that MySQL offers, and requires fast access. This could for example be session data in a dynamic web interface that needs to be accessed often and fast.

    Redis could also be used as a cache for some MySQL data which is going to be accessed very often (ie: load it when a user logs in).

    I think you're asking the question the wrong way around, you should ask yourself which one is more suited to an application, rather than which application is suited to a system ;)

提交回复
热议问题