Test Redis with a PHP client

NOTE: To use the example script below, you must have PHP installed on the server. You can check this by executing php -v. If you don’t have it available, you can easily install PHP on Debian with the command sudo apt-get install php5 or on CentOS with the command sudo yum install php.

Begin by extracting the contents of the downloaded archive and creating a simple script named example.php.

$ cd predis-1.0
$ nano example.php

The script begins by including the class autoloader file and instantiating an object of the class:

Notice that it configures the client object by defining the Redis server host, port and password. Replace these values with actual values for your server.

You can now use the object’s set() and get() methods to add or remove values from the cache. In this example, the set() method stores the value ‘cowabunga’ using the key ‘foo’. The key can then be used with the get() method to retrieve the original value whenever needed.