Choose Redis connection method


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.