Senior
What have you used for data caching? Redis, Rabbit?
sobes.tech AI
Answer from AI
Data caching is usually done with Redis, as it is a high-performance key-value store supporting various data structures and the ability to set key expiration times (TTL). RabbitMQ is a message broker designed for organizing queues and message exchange between services, but not for caching.
Example of using Redis for caching in PHP with the phpredis extension:
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
// Setting a value with a TTL of 3600 seconds
$redis->setex('cache_key', 3600, json_encode($data));
// Retrieving the value
$cachedData = $redis->get('cache_key');
if ($cachedData !== false) {
$data = json_decode($cachedData, true);
}