How to Connect to Redis Database via PHP

Posted on October 19, 2018 at 2:13 pm

First make sure to install PHP extension for Redis:

On Debian-like OS you can install it this way:

apt-get install php7.0-redis

Then you can connect to Redis via PHP this way:

$redis = new Redis(); 
    $connected = $redis->connect('', 6379, 1);
catch(Exception $e) 
    echo "Failed to connect to Redis database: ".$e->getMessage();
    echo "Failed to connect to Redis database";
$redis->set('key', 'value');

As you can see we handle connection issues.

Receive updates via email

Other Posts

Updated Posts