Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Redis

Redis is an in-memory key-value data store, used as a database, cache, message broker, or queue. It supports richer data structures than a plain key-value store, including hashes, lists, sets, sorted sets, and streams, and offers sub-millisecond latency thanks to its in-memory nature.

Redis can persist its dataset to disk, be replicated, and be clustered for high availability and horizontal scaling.

PHP applications talk to Redis mostly through the phpredis PECL C-extension, or through pure-PHP client libraries such as predis/predis. Frameworks like Symfony and Laravel ship built-in cache, session, and queue adapters backed by Redis.

<?php

    $redis = new Redis();
    $redis->connect('127.0.0.1', 6379);

    $redis->set('user:42', json_encode(['name' => 'Ada']));
    $user = json_decode($redis->get('user:42'), true);

?>

Documentation

See Also