11<?php
2+ /**
3+ * InitPHP/Redis
4+ *
5+ * This file is part of InitPHP Redis.
6+ *
7+ * @author Muhammet ŞAFAK <[email protected] > 8+ * @copyright Copyright © 2022 Muhammet ŞAFAK
9+ * @license ./LICENSE MIT
10+ * @version 1.0
11+ * @link https://www.muhammetsafak.com.tr
12+ */
213
314namespace InitPHP \Redis ;
415
1324
1425class Redis
1526{
27+
1628 protected array $ _Options = [
17- 'prefix ' => 'cache_ ' ,
29+ 'prefix ' => 'i_ ' ,
1830 'host ' => '127.0.0.1 ' ,
1931 'password ' => null ,
2032 'port ' => 6379 ,
@@ -27,7 +39,7 @@ class Redis
2739 public function __construct (array $ options = [])
2840 {
2941 if (!extension_loaded ('redis ' )){
30- throw new \RuntimeException ();
42+ throw new \RuntimeException (" The process has been terminated because the PHP Redis extension is not installed or enabled on your server. " );
3143 }
3244 $ this ->_Options = array_merge ($ this ->_Options , $ options );
3345 }
@@ -42,7 +54,7 @@ public function __destruct()
4254 /**
4355 * @return \Redis
4456 */
45- public function getRedis (): \Redis
57+ public final function getRedis (): \Redis
4658 {
4759 if (isset ($ this ->redis )){
4860 return $ this ->redis ;
@@ -81,8 +93,8 @@ public function get(string $key, $default = null)
8193 $ this ->validationName ($ name );
8294 if (($ data = $ this ->getRedis ()->get ($ name )) !== FALSE ){
8395 $ data = unserialize ($ data );
84- if (isset ($ data ['__cache_type ' ], $ data ['__cache_value ' ])){
85- return $ data ['__cache_value ' ];
96+ if (isset ($ data ['__type ' ], $ data ['__value ' ])){
97+ return $ data ['__value ' ];
8698 }
8799 }
88100 return $ this ->reDefault ($ default );
@@ -116,7 +128,7 @@ public function set(string $key, $value, $ttl = null): bool
116128 default :
117129 return false ;
118130 }
119- if (!($ this ->getRedis ()->set ($ name , serialize (['__cache_type ' => $ type , '__cache_value ' => $ value ])))){
131+ if (!($ this ->getRedis ()->set ($ name , serialize (['__type ' => $ type , '__value ' => $ value ])))){
120132 return false ;
121133 }
122134 if ($ ttl !== null ){
0 commit comments