2.8.1.5. Redis test

The process of configuring Redis to work is described in instruction.

Warning!

If a script interacting with Redis needs to run from console or through cron, then in the start command you must specify the path to php.ini one of the websites of the hosting account. Details are provided here.

To test how Redis works, run following script:

  1. <?php
  2. $mydir = explode('/', __DIR__);
  3. $redis = new Redis();
  4. $redis->connect("/home/$mydir[2]/.system/redis.sock");
  5. if (!$redis->get('int') && !$redis->get('string') && !$redis->get('another_string')) {
  6. $redis->set('string', 'variables were set at ' . date('F'));
  7. $redis->set('int', date('d'));
  8. $redis->set('another_string', date('G') . ":" . date('i'));
  9. }
  10. echo $redis->get('string') . " " . $redis->get('int') . ", " . $redis->get('another_string') . "<br>";
  11. var_dump($redis->get('int'));
  12. var_dump($redis->get('string'));
  13. var_dump($redis->get('another_string'));
  14. ?>

On first launch, the script writes the current date to Redis and displays it on the screen. On subsequent launches, the script displays the same date read from Redis.

Content