api de gestion de ticket, basé sur php-crud-api. Le but est de décorrélé les outils de gestion des données, afin
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

RedisCache.php 898B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace Tqdev\PhpCrudApi\Cache;
  3. class RedisCache implements Cache
  4. {
  5. protected $prefix;
  6. protected $redis;
  7. public function __construct(string $prefix, string $config)
  8. {
  9. $this->prefix = $prefix;
  10. if ($config == '') {
  11. $config = '127.0.0.1';
  12. }
  13. $params = explode(':', $config, 6);
  14. if (isset($params[3])) {
  15. $params[3] = null;
  16. }
  17. $this->redis = new \Redis();
  18. call_user_func_array(array($this->redis, 'pconnect'), $params);
  19. }
  20. public function set(string $key, string $value, int $ttl = 0): bool
  21. {
  22. return $this->redis->set($this->prefix . $key, $value, $ttl);
  23. }
  24. public function get(string $key): string
  25. {
  26. return $this->redis->get($this->prefix . $key) ?: '';
  27. }
  28. public function clear(): bool
  29. {
  30. return $this->redis->flushDb();
  31. }
  32. }