Selaa lähdekoodia

Se agrega la posibilidad de leer y escribir string. Sin realizar
json_encode / json_decode.

Maximiliano Schvindt 7 vuotta sitten
vanhempi
commit
e59cfe89d0
2 muutettua tiedostoa jossa 23 lisäystä ja 0 poistoa
  1. 4 0
      Services/CollectorInterface.php
  2. 19 0
      Services/RedisService.php

+ 4 - 0
Services/CollectorInterface.php

@@ -6,5 +6,9 @@ interface CollectorInterface
 {
     public function get($key);
     
+    public function getString($key);
+    
     public function set($key, $data);
+    
+    public function setString($key, $data);
 }

+ 19 - 0
Services/RedisService.php

@@ -42,6 +42,8 @@ class RedisService extends Redis implements CollectorInterface
         parent::disconnect();
         parent::quit();
 
+        if (is_null($data_cached)) $data_cached = array();
+        
         return $data_cached;
     }
 
@@ -87,4 +89,21 @@ class RedisService extends Redis implements CollectorInterface
 
         return $_data;
     }
+
+    /**
+     * @param string $key
+     * @param string $data
+     */
+    public function setString($key, $data, $output = false)
+    {
+        $_save = $data;
+
+        $start = microtime(true);
+        parent::setex($key, 3600, $_save);
+        $end = microtime(true);
+        $t = $end - $start;
+        if ($output) {
+            print_r("SETEX key '{$key}': {$t} segundos" . PHP_EOL);
+        }
+    }
 }