We have decided to use redis as a message broker for our relatively small project and information out there on how to setup and use redis in production is very minimal. We use redis on aws. I have consulted this example: https://redis4you.com/code.php?id=012 and tested with a redis server locally and everything works fine.
However we are torn between using a crontab and daemon service and not exactly sure which is the best though implementing the cron is the easiest. I have researched on the generally acceptable way of doing but seen nothing.
Using a crontab means that I would have to exit the Slave.php file at some point with the snippet below which I am not totally comfortable with
public function processMessageInQueue(){
while(!is_null($message_id = $this->predis->lpop("queue:message"))){
$message = $this->predis->hgetall("message:$message_id");
// Delete the key
$this->predis->del("message:$message_id");
// Process the message...
$message = json_decode($message['message_data'], 1);
$this->processMessage((array)$message);
}
exit(0);
}
Is there a better way of doing this or must it be done with either cron or a daemon service?