Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
UserAdminV2
Overview
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
庄欣
UserAdminV2
Commits
244d4bfd
Commit
244d4bfd
authored
13 years ago
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bugs in Redis class.
parent
13a70bcc
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
6 deletions
+37
-6
application/config/database.php
+5
-1
laravel/redis.php
+32
-5
No files found.
application/config/database.php
View file @
244d4bfd
...
...
@@ -113,7 +113,11 @@ return array(
'redis'
=>
array
(
'default'
=>
array
(
'host'
=>
'127.0.0.1'
,
'port'
=>
6379
),
'default'
=>
array
(
'host'
=>
'127.0.0.1'
,
'port'
=>
6379
,
'database'
=>
0
),
),
...
...
This diff is collapsed.
Click to expand it.
laravel/redis.php
View file @
244d4bfd
...
...
@@ -17,6 +17,13 @@ class Redis {
protected
$port
;
/**
* The databse number the connection selects on load.
*
* @var int
*/
protected
$database
;
/**
* The connection to the Redis database.
*
* @var resource
...
...
@@ -35,12 +42,14 @@ class Redis {
*
* @param string $host
* @param string $port
* @param int $database
* @return void
*/
public
function
__construct
(
$host
,
$port
)
public
function
__construct
(
$host
,
$port
,
$database
=
0
)
{
$this
->
host
=
$host
;
$this
->
port
=
$port
;
$this
->
database
=
$database
;
}
/**
...
...
@@ -68,7 +77,9 @@ class Redis {
throw
new
\Exception
(
"Redis database [
$name
] is not defined."
);
}
static
::
$databases
[
$name
]
=
new
static
(
$config
[
'host'
],
$config
[
'port'
]);
extract
(
$config
);
static
::
$databases
[
$name
]
=
new
static
(
$host
,
$port
,
$database
);
}
return
static
::
$databases
[
$name
];
...
...
@@ -95,6 +106,17 @@ class Redis {
$response
=
trim
(
fgets
(
$this
->
connection
,
512
));
return
$this
->
parse
(
$response
);
}
/**
* Parse and return the response from the Redis database.
*
* @param string $response
* @return mixed
*/
protected
function
parse
(
$response
)
{
switch
(
substr
(
$response
,
0
,
1
))
{
case
'-'
:
...
...
@@ -131,6 +153,8 @@ class Redis {
throw
new
\Exception
(
"Error making Redis connection:
{
$error
}
-
{
$message
}
"
);
}
$this
->
select
(
$this
->
database
);
return
$this
->
connection
;
}
...
...
@@ -191,6 +215,8 @@ class Redis {
list
(
$read
,
$response
,
$size
)
=
array
(
0
,
''
,
substr
(
$head
,
1
));
if
(
$size
>
0
)
{
do
{
// Calculate and read the appropriate bytes off of the Redis response.
...
...
@@ -203,6 +229,7 @@ class Redis {
$read
+=
$block
;
}
while
(
$read
<
$size
);
}
// The response ends with a trailing CRLF. So, we need to read that off
// of the end of the file stream to get it out of the way of the next
...
...
@@ -225,11 +252,11 @@ class Redis {
$response
=
array
();
// Iterate through each bulk response in the multi-bulk and parse it out
// using the "
bulk" method since a multi-bulk response is just a list of
//
plain old bulk
responses.
// using the "
parse" method since a multi-bulk response is just a list
//
of plain old Redis database
responses.
for
(
$i
=
0
;
$i
<
$count
;
$i
++
)
{
$response
[]
=
$this
->
bulk
(
trim
(
fgets
(
$this
->
connection
,
512
)));
$response
[]
=
$this
->
parse
(
trim
(
fgets
(
$this
->
connection
,
512
)));
}
return
$response
;
...
...
This diff is collapsed.
Click to expand it.
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