PHP – Redis

Talking to Redis from PHP is easy now. 

We need to install Redis client for PHP and HHVM from packagist or composer

In order to use Redis with PHP you will need to PHP Redis client.

Installing Predis

composer require predis/predis

Opening a Connection to Redis Using Predis

<?php require “predis/autoload.php”; Predis\Autoloader::register(); $redis = new Predis\Client(array( “scheme” => “tcp”, “host” => “hostname”, “port” => port, “password” => “password”)); echo “Connected to Redis”; ?>

Reading and Writing Data with Predis

// open a connection to Redis …

$redis->set(“foo”, “bar”);

$value = $redis->get(“foo”);

var_dump($value);

Leave a Reply

Your email address will not be published. Required fields are marked *