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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
b84097c1
Commit
b84097c1
authored
Aug 12, 2013
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed redis response parsing for large data
fixes #743
parent
a5a64dd7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
7 deletions
+52
-7
Connection.php
framework/yii/db/redis/Connection.php
+12
-6
RedisCacheTest.php
tests/unit/framework/caching/RedisCacheTest.php
+40
-1
No files found.
framework/yii/db/redis/Connection.php
View file @
b84097c1
...
@@ -371,7 +371,7 @@ class Connection extends Component
...
@@ -371,7 +371,7 @@ class Connection extends Component
array_unshift
(
$params
,
$name
);
array_unshift
(
$params
,
$name
);
$command
=
'*'
.
count
(
$params
)
.
"
\r\n
"
;
$command
=
'*'
.
count
(
$params
)
.
"
\r\n
"
;
foreach
(
$params
as
$arg
)
{
foreach
(
$params
as
$arg
)
{
$command
.=
'$'
.
strlen
(
$arg
)
.
"
\r\n
"
.
$arg
.
"
\r\n
"
;
$command
.=
'$'
.
mb_strlen
(
$arg
,
'8bit'
)
.
"
\r\n
"
.
$arg
.
"
\r\n
"
;
}
}
\Yii
::
trace
(
"Executing Redis Command:
{
$name
}
"
,
__CLASS__
);
\Yii
::
trace
(
"Executing Redis Command:
{
$name
}
"
,
__CLASS__
);
...
@@ -382,11 +382,11 @@ class Connection extends Component
...
@@ -382,11 +382,11 @@ class Connection extends Component
private
function
parseResponse
(
$command
)
private
function
parseResponse
(
$command
)
{
{
if
((
$line
=
fgets
(
$this
->
_socket
))
===
false
)
{
if
((
$line
=
fgets
(
$this
->
_socket
))
===
false
)
{
throw
new
Exception
(
"Failed to read from socket.
\n
Redis command was: "
.
$command
);
throw
new
Exception
(
"Failed to read from socket.
\n
Redis command was: "
.
$command
);
}
}
$type
=
$line
[
0
];
$type
=
$line
[
0
];
$line
=
substr
(
$line
,
1
,
-
2
);
$line
=
mb_substr
(
$line
,
1
,
-
2
,
'8bit'
);
switch
(
$type
)
switch
(
$type
)
{
{
case
'+'
:
// Status reply
case
'+'
:
// Status reply
...
@@ -400,10 +400,16 @@ class Connection extends Component
...
@@ -400,10 +400,16 @@ class Connection extends Component
if
(
$line
==
'-1'
)
{
if
(
$line
==
'-1'
)
{
return
null
;
return
null
;
}
}
if
((
$data
=
fread
(
$this
->
_socket
,
$line
+
2
))
===
false
)
{
$length
=
$line
+
2
;
throw
new
Exception
(
"Failed to read from socket.
\n
Redis command was: "
.
$command
);
$data
=
''
;
while
(
$length
>
0
)
{
if
((
$block
=
fread
(
$this
->
_socket
,
$line
+
2
))
===
false
)
{
throw
new
Exception
(
"Failed to read from socket.
\n
Redis command was: "
.
$command
);
}
$data
.=
$block
;
$length
-=
mb_strlen
(
$block
,
'8bit'
);
}
}
return
substr
(
$data
,
0
,
-
2
);
return
mb_substr
(
$data
,
0
,
-
2
,
'8bit'
);
case
'*'
:
// Multi-bulk replies
case
'*'
:
// Multi-bulk replies
$count
=
(
int
)
$line
;
$count
=
(
int
)
$line
;
$data
=
array
();
$data
=
array
();
...
...
tests/unit/framework/caching/RedisCacheTest.php
View file @
b84097c1
...
@@ -7,7 +7,7 @@ use yiiunit\TestCase;
...
@@ -7,7 +7,7 @@ use yiiunit\TestCase;
/**
/**
* Class for testing redis cache backend
* Class for testing redis cache backend
*/
*/
class
RedisCacheTest
extends
CacheTest
class
RedisCacheTest
extends
CacheTest
Case
{
{
private
$_cacheInstance
=
null
;
private
$_cacheInstance
=
null
;
...
@@ -20,6 +20,7 @@ class RedisCacheTest extends CacheTest
...
@@ -20,6 +20,7 @@ class RedisCacheTest extends CacheTest
'hostname'
=>
'localhost'
,
'hostname'
=>
'localhost'
,
'port'
=>
6379
,
'port'
=>
6379
,
'database'
=>
0
,
'database'
=>
0
,
'dataTimeout'
=>
0.1
,
);
);
$dsn
=
$config
[
'hostname'
]
.
':'
.
$config
[
'port'
];
$dsn
=
$config
[
'hostname'
]
.
':'
.
$config
[
'port'
];
if
(
!@
stream_socket_client
(
$dsn
,
$errorNumber
,
$errorDescription
,
0.5
))
{
if
(
!@
stream_socket_client
(
$dsn
,
$errorNumber
,
$errorDescription
,
0.5
))
{
...
@@ -42,4 +43,41 @@ class RedisCacheTest extends CacheTest
...
@@ -42,4 +43,41 @@ class RedisCacheTest extends CacheTest
usleep
(
300000
);
usleep
(
300000
);
$this
->
assertFalse
(
$cache
->
get
(
'expire_test_ms'
));
$this
->
assertFalse
(
$cache
->
get
(
'expire_test_ms'
));
}
}
/**
* Store a value that is 2 times buffer size big
* https://github.com/yiisoft/yii2/issues/743
*/
public
function
testLargeData
()
{
$cache
=
$this
->
getCacheInstance
();
$data
=
str_repeat
(
'XX'
,
8192
);
// http://www.php.net/manual/en/function.fread.php
$key
=
'bigdata1'
;
$this
->
assertFalse
(
$cache
->
get
(
$key
));
$cache
->
set
(
$key
,
$data
);
$this
->
assertTrue
(
$cache
->
get
(
$key
)
===
$data
);
// try with multibyte string
$data
=
str_repeat
(
'ЖЫ'
,
8192
);
// http://www.php.net/manual/en/function.fread.php
$key
=
'bigdata2'
;
$this
->
assertFalse
(
$cache
->
get
(
$key
));
$cache
->
set
(
$key
,
$data
);
$this
->
assertTrue
(
$cache
->
get
(
$key
)
===
$data
);
}
public
function
testMultiByteGetAndSet
()
{
$cache
=
$this
->
getCacheInstance
();
$data
=
array
(
'abc'
=>
'ежик'
,
2
=>
'def'
);
$key
=
'data1'
;
$this
->
assertFalse
(
$cache
->
get
(
$key
));
$cache
->
set
(
$key
,
$data
);
$this
->
assertTrue
(
$cache
->
get
(
$key
)
===
$data
);
}
}
}
\ No newline at end of file
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