@@ -61,12 +61,28 @@ public function __construct(array $options = [])
6161 $ this ->options = array_merge ($ this ->options , $ options );
6262 }
6363
64- $ this ->handler = new \Redis ;
65- $ this ->handler ->connect ($ this ->options ['host ' ], (int ) $ this ->options ['port ' ], (int ) $ this ->options ['timeout ' ]);
66- if ('' != $ this ->options ['password ' ]) {
67- $ this ->handler ->auth ($ this ->options ['password ' ]);
64+ if (extension_loaded ('redis ' )) {
65+ $ this ->handler = new \Redis ;
66+ $ this ->handler ->connect ($ this ->options ['host ' ], (int ) $ this ->options ['port ' ], (int ) $ this ->options ['timeout ' ]);
67+ if ('' != $ this ->options ['password ' ]) {
68+ $ this ->handler ->auth ($ this ->options ['password ' ]);
69+ }
70+ } elseif (class_exists ('\Predis\Client ' )) {
71+ $ params = [];
72+ foreach ($ this ->options as $ key => $ val ) {
73+ if (in_array ($ key , ['aggregate ' , 'cluster ' , 'connections ' , 'exceptions ' , 'prefix ' , 'profile ' , 'replication ' , 'parameters ' ])) {
74+ $ params [$ key ] = $ val ;
75+ unset($ this ->options [$ key ]);
76+ }
77+ }
78+ if ('' == $ this ->options ['password ' ]) {
79+ unset($ this ->options ['password ' ]);
80+ }
81+ $ this ->handler = new \Predis \Client ($ this ->options , $ params );
82+ $ this ->options ['prefix ' ] = '' ;
83+ } else {
84+ throw new BadFunctionCallException ('not support: redis ' );
6885 }
69-
7086 if (0 != $ this ->options ['select ' ]) {
7187 $ this ->handler ->select ((int ) $ this ->options ['select ' ]);
7288 }
@@ -234,7 +250,11 @@ public function getTagItems($tag): array
234250 */
235251 public function close ()
236252 {
237- $ this ->handler ->close ();
253+ if (method_exists ($ this ->handler , 'close ' )) {
254+ $ this ->handler ->close ();
255+ } else {
256+ $ this ->handler ->quit ();
257+ }
238258 $ this ->handler = null ;
239259 }
240260}
0 commit comments