Redis connection test script

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
require "../predis/autoload.php";  // Update with your location to predis
Predis\Autoloader::register();


try {
    $redis = new Predis\Client();
    // Uncomment the following lines and adjust them accordingly if you have a non-default redis configuration
/*
    $redis = new Predis\Client(array(
        "scheme" => "tcp",
        "host" => "127.0.0.1",
        "port" => 6379));
*/

    echo "Connected to Redis";
}
catch (Exception $e) {
    echo "Unable to connect to Redis";
    echo $e->getMessage();
}

$redis->set("var1", "The value for var1 is me");
echo $redis->get("var1");

// You can alos use exits() function to test if a variable exists or not
echo ($redis->exists("var2")) ? "true" : "false";
This entry was posted in php, Web Development. Bookmark the permalink.

Leave a Reply

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


+ 1 = five