Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
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
Yeray Santana Hualde
syncEnrollments
Commits
bd669584
Commit
bd669584
authored
Oct 25, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring.
parent
a6d487ec
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
25 deletions
+11
-25
redis.php
laravel/redis.php
+11
-25
No files found.
laravel/redis.php
View file @
bd669584
...
...
@@ -2,13 +2,6 @@
class
Redis
{
/**
* The active Redis connections.
*
* @var array
*/
protected
static
$connections
=
array
();
/**
* The name of the Redis connection.
*
...
...
@@ -28,7 +21,7 @@ class Redis {
*
* @var resource
*/
protected
$connection
;
protected
static
$connection
;
/**
* Create a new Redis connection instance.
...
...
@@ -58,28 +51,21 @@ class Redis {
/**
* Create a new Redis connection instance.
*
*
Redis connections are managed as singletons
, so if the connection has
*
The Redis connection is managed as a singleton
, so if the connection has
* already been established, that same connection instance will be returned
* on subsequent requests for the connection.
*
* @param string $connection
* @return Redis
*/
public
static
function
connection
(
$name
)
public
static
function
connection
()
{
if
(
!
array_key_exists
(
$name
,
static
::
$connections
))
if
(
is_null
(
static
::
$connection
))
{
$config
=
Config
::
get
(
"database.redis.
{
$name
}
"
);
if
(
is_null
(
$config
))
{
throw
new
\Exception
(
"Redis connection [
$name
] has not been configured."
);
}
static
::
$connections
[
$name
]
=
static
::
make
(
$name
,
$config
)
->
connect
();
static
::
$connection
=
static
::
make
(
$name
,
Config
::
get
(
'database.redis'
))
->
connect
();
}
return
static
::
$connection
s
[
$name
]
;
return
static
::
$connection
;
}
/**
...
...
@@ -91,9 +77,9 @@ class Redis {
*/
public
function
connect
()
{
$this
->
connection
=
@
fsockopen
(
$this
->
config
[
'host'
],
$this
->
config
[
'port'
],
$error
,
$message
);
static
::
$
connection
=
@
fsockopen
(
$this
->
config
[
'host'
],
$this
->
config
[
'port'
],
$error
,
$message
);
if
(
$this
->
connection
===
false
)
if
(
static
::
$
connection
===
false
)
{
throw
new
\Exception
(
"Error establishing Redis connection [
{
$this
->
name
}
]:
{
$error
}
-
{
$message
}
"
);
}
...
...
@@ -110,9 +96,9 @@ class Redis {
*/
public
function
run
(
$method
,
$parameters
)
{
fwrite
(
$this
->
connection
,
$this
->
command
(
$method
,
$parameters
));
fwrite
(
static
::
$
connection
,
$this
->
command
(
$method
,
$parameters
));
$reply
=
trim
(
fgets
(
$this
->
connection
,
512
));
$reply
=
trim
(
fgets
(
static
::
$
connection
,
512
));
}
/**
...
...
@@ -149,7 +135,7 @@ class Redis {
*/
public
function
__destruct
()
{
fclose
(
$this
->
connection
);
fclose
(
static
::
$
connection
);
}
}
\ 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