If you use swoole, do you still need to use redis?

for example, I have a variable that needs to store a list of online users. I declare a global variable directly in the swoole server file and store the information of each online user in the form of a two-dimensional array. Swoole itself is resident in memory. In this case, do I still have to use redis to store this variable?

Jul.08,2022

depending on the requirements, the advantage of storing in memory is that there is no network loss and fast reading speed, but there is no service restart, and data cannot be shared across services. If the data is only part of the running state, it is not necessary to use redis . If the data security requirements are high, and multiple services are required to read, then it is convenient to use redis .


this depends on your specific needs. If you need to share the user's status, you still have to redis.


you have two situations for this requirement:

  1. swoole server only starts one process, and you have no problem using global variables. But we should pay attention to the influence of the cooperation process.
  2. swoole server multiple processes are started. The global table can only represent the number of users of the current process, not all users. You need to rely on third parties such as redis .

you can try the one framework, which contains shared data between processes, and atomic operations do not have to consider the problem of multi-process cooperation.


it is recommended to use redis. Memory tables have no advantage except for faster speed.


another advantage of using redis is that other servers can share data and save it. Take

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b38300-344be.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b38300-344be.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?