Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
yii2
Commits
cfe87460
Commit
cfe87460
authored
Nov 13, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed return type for redis simple strings
fixes #4745
parent
2de384e3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
5 deletions
+39
-5
CHANGELOG.md
extensions/redis/CHANGELOG.md
+1
-2
Connection.php
extensions/redis/Connection.php
+12
-3
RedisConnectionTest.php
tests/unit/extensions/redis/RedisConnectionTest.php
+26
-0
No files found.
extensions/redis/CHANGELOG.md
View file @
cfe87460
...
...
@@ -4,8 +4,7 @@ Yii Framework 2 redis extension Change Log
2.
0.1 under development
-----------------------
-
no changes in this release.
-
Bug #4745: value of simple string returns was ignored by redis client and
`true`
is returned instead, now only
`OK`
will result in a
`true`
while all other values are returned as is (cebe)
2.
0.0 October 12, 2014
----------------------
...
...
extensions/redis/Connection.php
View file @
cfe87460
...
...
@@ -337,7 +337,8 @@ class Connection extends Component
* @return array|bool|null|string Dependent on the executed command this method
* will return different data types:
*
* - `true` for commands that return "status reply".
* - `true` for commands that return "status reply" with the message `'OK'` or `'PONG'`.
* - `string` for commands that return "status reply" that does not have the message `OK` (since version 2.0.1).
* - `string` for commands that return "integer reply"
* as the value is in the range of a signed 64 bit integer.
* - `string` or `null` for commands that return "bulk reply".
...
...
@@ -363,6 +364,11 @@ class Connection extends Component
return
$this
->
parseResponse
(
implode
(
' '
,
$params
));
}
/**
* @param string $command
* @return mixed
* @throws Exception on error
*/
private
function
parseResponse
(
$command
)
{
if
((
$line
=
fgets
(
$this
->
_socket
))
===
false
)
{
...
...
@@ -372,8 +378,11 @@ class Connection extends Component
$line
=
mb_substr
(
$line
,
1
,
-
2
,
'8bit'
);
switch
(
$type
)
{
case
'+'
:
// Status reply
return
true
;
if
(
$line
===
'OK'
||
$line
===
'PONG'
)
{
return
true
;
}
else
{
return
$line
;
}
case
'-'
:
// Error reply
throw
new
Exception
(
"Redis error: "
.
$line
.
"
\n
Redis command was: "
.
$command
);
case
':'
:
// Integer reply
...
...
tests/unit/extensions/redis/RedisConnectionTest.php
View file @
cfe87460
...
...
@@ -53,4 +53,30 @@ class RedisConnectionTest extends RedisTestCase
$db
->
set
(
'hi'
,
$data
);
$this
->
assertEquals
(
$data
,
$db
->
get
(
'hi'
));
}
/**
* https://github.com/yiisoft/yii2/issues/4745
*/
public
function
testReturnType
()
{
$redis
=
$this
->
getConnection
();
$redis
->
executeCommand
(
'SET'
,[
'key1'
,
'val1'
]);
$redis
->
executeCommand
(
'HMSET'
,[
'hash1'
,
'hk3'
,
'hv3'
,
'hk4'
,
'hv4'
]);
$redis
->
executeCommand
(
'RPUSH'
,[
'newlist2'
,
'tgtgt'
,
'tgtt'
,
'44'
,
11
]);
$redis
->
executeCommand
(
'SADD'
,[
'newset2'
,
'segtggttval'
,
'sv1'
,
'sv2'
,
'sv3'
]);
$redis
->
executeCommand
(
'ZADD'
,[
'newz2'
,
2
,
'ss'
,
3
,
'pfpf'
]);
$allKeys
=
$redis
->
executeCommand
(
'KEYS'
,[
'*'
]);
sort
(
$allKeys
);
$this
->
assertEquals
([
'hash1'
,
'key1'
,
'newlist2'
,
'newset2'
,
'newz2'
],
$allKeys
);
$expected
=
[
'hash1'
=>
'hash'
,
'key1'
=>
'string'
,
'newlist2'
=>
'list'
,
'newset2'
=>
'set'
,
'newz2'
=>
'zset'
,
];
foreach
(
$allKeys
as
$key
)
{
$this
->
assertEquals
(
$expected
[
$key
],
$redis
->
executeCommand
(
'TYPE'
,[
$key
]));
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment