Redis.php 794 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace Queue\Src;
  3. use Dever;
  4. class Redis implements QueueInterface
  5. {
  6. private $db;
  7. public function __construct()
  8. {
  9. $this->db = new \Redis;
  10. $config = Dever::config('base')->queue;
  11. $host = Dever::config('base')->queue['host'];
  12. $port = Dever::config('base')->queue['port'];
  13. $this->db->connect($config['host'], $config['port']);
  14. if (isset($config['password'])) {
  15. $this->db->auth($config['password']);
  16. }
  17. if (isset($config['key']) && $config['key']) {
  18. $this->key = $config['key'];
  19. }
  20. }
  21. public function push($value, $key)
  22. {
  23. return $this->db->rpush($key, $value);
  24. }
  25. public function pop($key)
  26. {
  27. $data = $this->db->lpop($key);
  28. if ($data) {
  29. return $data;
  30. }
  31. return false;
  32. }
  33. public function len($key)
  34. {
  35. return $this->db->llen($key);
  36. }
  37. }