@@ -51,7 +51,7 @@ function __construct($host, $port = 6379) {
51
51
$ this ->port = $ port ;
52
52
$ this ->__sock = fsockopen ($ this ->host , $ this ->port , $ errno , $ errstr );
53
53
if (!$ this ->__sock ) {
54
- throw new \ Exception ("{$ errno } - {$ errstr }" );
54
+ throw new Exception ("{$ errno } - {$ errstr }" );
55
55
}
56
56
}
57
57
@@ -63,15 +63,13 @@ function __call($name, $args) {
63
63
64
64
/* Build the Redis unified protocol command */
65
65
array_unshift ($ args , strtoupper ($ name ));
66
- $ command = sprintf ('*%d%s%s%s ' , count ($ args ), CRLF , implode (array_map (function ($ arg ) {
67
- return sprintf ('$%d%s%s ' , strlen ($ arg ), CRLF , $ arg );
68
- }, $ args ), CRLF ), CRLF );
66
+ $ command = sprintf ('*%d%s%s%s ' , count ($ args ), CRLF , implode (array_map (array ($ this , 'formatArgument ' ), $ args ), CRLF ), CRLF );
69
67
70
68
/* Open a Redis connection and execute the command */
71
69
for ($ written = 0 ; $ written < strlen ($ command ); $ written += $ fwrite ) {
72
70
$ fwrite = fwrite ($ this ->__sock , substr ($ command , $ written ));
73
71
if ($ fwrite === FALSE ) {
74
- throw new \ Exception ('Failed to write entire command to stream ' );
72
+ throw new Exception ('Failed to write entire command to stream ' );
75
73
}
76
74
}
77
75
@@ -139,4 +137,7 @@ function __call($name, $args) {
139
137
return $ response ;
140
138
}
141
139
140
+ private function formatArgument ($ arg ) {
141
+ return sprintf ('$%d%s%s ' , strlen ($ arg ), CRLF , $ arg );
142
+ }
142
143
}
0 commit comments