You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

40 rivejä
1.1 KiB

  1. <?php
  2. /**
  3. * Memcached MQ
  4. *
  5. * - 队列存放于Memcached/Memcache,但须注意MC默认情况下单个key最大只支持1M大小
  6. *
  7. * @author dogstar <chanzonghuang@gmail.com> 20160430
  8. */
  9. class Task_MQ_Memcached extends Task_MQ_KeyValue {
  10. public function __construct(PhalApi_Cache $mcCache = NULL) {
  11. if ($mcCache === NULL) {
  12. $config = DI()->config->get('app.Task.mq.mc');
  13. if (!isset($config['host'])) {
  14. $config['host'] = '127.0.0.1';
  15. }
  16. if (!isset($config['port'])) {
  17. $config['port'] = 11211;
  18. }
  19. //优先使用memcached
  20. $mcCache = extension_loaded('memcached')
  21. ? new PhalApi_Cache_Memcached($config)
  22. : new PhalApi_Cache_Memcache($config);
  23. }
  24. $mcCache->set('123123', time(), 31536000);
  25. parent::__construct($mcCache);
  26. }
  27. /**
  28. * 最大缓存时间,29天,因为MC的过期时间不能超过30天
  29. */
  30. protected function getExpireTime() {
  31. return 2505600;
  32. }
  33. }