Skip to content

Commit 110660b

Browse files
author
Alexander Cheprasov
committed
Removed params checker for optimization
1 parent 7e138c5 commit 110660b

31 files changed

+403
-632
lines changed

src/RedisClient/Command/Parameter/Parameter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ public static function address($param) {
2424
$param = explode(':', trim($param), 2);
2525
}
2626
if (is_array($param)) {
27-
if (isset($param[0]) && isset($param[1])) {
27+
if (isset($param[0], $param[1])) {
2828
return [
2929
static::string($param[0]),
3030
static::port($param[1]),
3131
];
32-
} elseif (isset($param['ip']) && isset($param['port'])) {
32+
} elseif (isset($param['ip'], $param['port'])) {
3333
return [
3434
static::string($param['ip']),
3535
static::port($param['port']),
@@ -114,7 +114,7 @@ public static function bit($bit) {
114114
* @return string[]
115115
*/
116116
public static function command($command) {
117-
return preg_split('/\s+/', $command);
117+
return explode(' ', $command);
118118
}
119119

120120
/**

src/RedisClient/Command/Traits/Version2x6/ConnectionCommandsTrait.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
*/
1111
namespace RedisClient\Command\Traits\Version2x6;
1212

13-
use RedisClient\Command\Parameter\Parameter;
14-
1513
/**
1614
* Connection
1715
* @link http://redis.io/commands#connection
@@ -27,7 +25,7 @@ trait ConnectionCommandsTrait {
2725
* @return bool True
2826
*/
2927
public function auth($password) {
30-
return $this->returnCommand(['AUTH'], [Parameter::string($password)]);
28+
return $this->returnCommand(['AUTH'], [$password]);
3129
}
3230

3331
/**
@@ -39,7 +37,7 @@ public function auth($password) {
3937
* @return string Returns message
4038
*/
4139
public function echoMessage($message) {
42-
return $this->returnCommand(['ECHO'], [Parameter::string($message)]);
40+
return $this->returnCommand(['ECHO'], [$message]);
4341
}
4442

4543
/**
@@ -51,7 +49,7 @@ public function echoMessage($message) {
5149
* @return string Returns message
5250
*/
5351
public function ping($message = null) {
54-
return $this->returnCommand(['PING'], isset($message) ? [Parameter::string($message)] : null);
52+
return $this->returnCommand(['PING'], isset($message) ? [$message] : null);
5553
}
5654

5755
/**
@@ -74,7 +72,7 @@ public function quit() {
7472
* @return bool
7573
*/
7674
public function select($db) {
77-
return $this->returnCommand(['SELECT'], [Parameter::integer($db)]);
75+
return $this->returnCommand(['SELECT'], [$db]);
7876
}
7977

8078
}

src/RedisClient/Command/Traits/Version2x6/HashesCommandsTrait.php

Lines changed: 13 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ trait HashesCommandsTrait {
3131
* not including specified but non existing fields.
3232
*/
3333
public function hdel($key, $fields) {
34-
return $this->returnCommand(['HDEL'], [
35-
Parameter::key($key),
36-
Parameter::keys($fields),
37-
]);
34+
return $this->returnCommand(['HDEL'], [$key, (array) $fields]);
3835
}
3936

4037
/**
@@ -48,10 +45,7 @@ public function hdel($key, $fields) {
4845
* @return int 1 if the hash contains field. 0 if the hash does not contain field, or key does not exist.
4946
*/
5047
public function hexists($key, $field) {
51-
return $this->returnCommand(['HEXISTS'], [
52-
Parameter::key($key),
53-
Parameter::key($field),
54-
]);
48+
return $this->returnCommand(['HEXISTS'], [$key, $field]);
5549
}
5650

5751
/**
@@ -66,10 +60,7 @@ public function hexists($key, $field) {
6660
* or nil when field is not present in the hash or key does not exist.
6761
*/
6862
public function hget($key, $field) {
69-
return $this->returnCommand(['HGET'], [
70-
Parameter::key($key),
71-
Parameter::key($field),
72-
]);
63+
return $this->returnCommand(['HGET'], [$key, $field]);
7364
}
7465

7566
/**
@@ -83,7 +74,7 @@ public function hget($key, $field) {
8374
* or an empty list when key does not exist.
8475
*/
8576
public function hgetall($key) {
86-
return $this->returnCommand(['HGETALL'], [Parameter::key($key)], ResponseParser::PARSE_ASSOC_ARRAY);
77+
return $this->returnCommand(['HGETALL'], [$key], ResponseParser::PARSE_ASSOC_ARRAY);
8778
}
8879

8980
/**
@@ -98,11 +89,7 @@ public function hgetall($key) {
9889
* @return int The value at field after the increment operation.
9990
*/
10091
public function hincrby($key, $field, $increment) {
101-
return $this->returnCommand(['HINCRBY'], [
102-
Parameter::key($key),
103-
Parameter::key($field),
104-
Parameter::integer($increment),
105-
]);
92+
return $this->returnCommand(['HINCRBY'], [$key, $field, $increment]);
10693
}
10794

10895
/**
@@ -117,11 +104,7 @@ public function hincrby($key, $field, $increment) {
117104
* @return string The value of field after the increment.
118105
*/
119106
public function hincrbyfloat($key, $field, $increment) {
120-
return $this->returnCommand(['HINCRBYFLOAT'], [
121-
Parameter::key($key),
122-
Parameter::key($field),
123-
Parameter::float($increment),
124-
]);
107+
return $this->returnCommand(['HINCRBYFLOAT'], [$key, $field, $increment]);
125108
}
126109

127110
/**
@@ -134,7 +117,7 @@ public function hincrbyfloat($key, $field, $increment) {
134117
* @return string[] List of fields in the hash, or an empty list when key does not exist.
135118
*/
136119
public function hkeys($key) {
137-
return $this->returnCommand(['HKEYS'], [Parameter::key($key)]);
120+
return $this->returnCommand(['HKEYS'], [$key]);
138121
}
139122

140123
/**
@@ -147,7 +130,7 @@ public function hkeys($key) {
147130
* @return int Number of fields in the hash, or 0 when key does not exist.
148131
*/
149132
public function hlen($key) {
150-
return $this->returnCommand(['HLEN'], [Parameter::key($key)]);
133+
return $this->returnCommand(['HLEN'], [$key]);
151134
}
152135

153136
/**
@@ -161,10 +144,7 @@ public function hlen($key) {
161144
* @return array List of values associated with the given fields, in the same order as they are requested.
162145
*/
163146
public function hmget($key, $fields) {
164-
return $this->returnCommand(['HMGET'], [
165-
Parameter::key($key),
166-
Parameter::keys($fields),
167-
]);
147+
return $this->returnCommand(['HMGET'], [$key, (array) $fields]);
168148
}
169149

170150
/**
@@ -176,10 +156,7 @@ public function hmget($key, $fields) {
176156
* @return bool True
177157
*/
178158
public function hmset($key, array $fieldValues) {
179-
return $this->returnCommand(['HMSET'], [
180-
Parameter::key($key),
181-
Parameter::assocArray($fieldValues),
182-
]);
159+
return $this->returnCommand(['HMSET'], [$key, Parameter::assocArray($fieldValues)]);
183160
}
184161

185162
/**
@@ -195,11 +172,7 @@ public function hmset($key, array $fieldValues) {
195172
* 0 if field already exists in the hash and the value was updated.
196173
*/
197174
public function hset($key, $field, $value) {
198-
return $this->returnCommand(['HSET'], [
199-
Parameter::key($key),
200-
Parameter::key($field),
201-
Parameter::string($value),
202-
]);
175+
return $this->returnCommand(['HSET'], [$key, $field, $value]);
203176
}
204177

205178
/**
@@ -214,11 +187,7 @@ public function hset($key, $field, $value) {
214187
* 0 if field already exists in the hash and no operation was performed.
215188
*/
216189
public function hsetnx($key, $field, $value) {
217-
return $this->returnCommand(['HSETNX'], [
218-
Parameter::key($key),
219-
Parameter::key($field),
220-
Parameter::string($value),
221-
]);
190+
return $this->returnCommand(['HSETNX'], [$key, $field, $value]);
222191
}
223192

224193
/**
@@ -231,7 +200,7 @@ public function hsetnx($key, $field, $value) {
231200
* @return string[] List of values in the hash, or an empty list when key does not exist.
232201
*/
233202
public function hvals($key) {
234-
return $this->returnCommand(['HVALS'], [Parameter::key($key)]);
203+
return $this->returnCommand(['HVALS'], [$key]);
235204
}
236205

237206
}

0 commit comments

Comments
 (0)