Posted By

archangel on 05/02/11


Tagged

redis predis


Versions (?)

Choose Redis connection method


 / Published in: PHP
 

Will try and connect via php-redis, and will fall back to Predis if it can not find php-redis

  1. <?php
  2. define('R_HOST', "127.0.0.1");
  3. define('R_PORT', 6379);
  4. define('R_DATA', "3");
  5. define('R_PASS', ""); # Leave blank for none
  6.  
  7. if(class_exists('Redis')) { # We have php-redis installed, and its faster than Predis
  8. $redis = new Redis();
  9. $redis->connect(R_HOST, R_PORT, 2.5);
  10. if(R_PASS)
  11. $redis->auth(R_PASS);
  12. $redis->select(R_DATA);
  13. } else {
  14. require './Predis/Predis.php';
  15. $redis = new Predis_Client(array(
  16. 'host' => R_HOST,
  17. 'port' => R_POST,
  18. 'database' => R_DATA,
  19. 'password' => R_PASS
  20. ));
  21. }
  22. ?>

Report this snippet  

You need to login to post a comment.