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
Show 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 @@
...
@@ -2,13 +2,6 @@
class
Redis
{
class
Redis
{
/**
* The active Redis connections.
*
* @var array
*/
protected
static
$connections
=
array
();
/**
/**
* The name of the Redis connection.
* The name of the Redis connection.
*
*
...
@@ -28,7 +21,7 @@ class Redis {
...
@@ -28,7 +21,7 @@ class Redis {
*
*
* @var resource
* @var resource
*/
*/
protected
$connection
;
protected
static
$connection
;
/**
/**
* Create a new Redis connection instance.
* Create a new Redis connection instance.
...
@@ -58,28 +51,21 @@ class Redis {
...
@@ -58,28 +51,21 @@ class Redis {
/**
/**
* Create a new Redis connection instance.
* 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
* already been established, that same connection instance will be returned
* on subsequent requests for the connection.
* on subsequent requests for the connection.
*
*
* @param string $connection
* @param string $connection
* @return Redis
* @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
}
"
);
static
::
$connection
=
static
::
make
(
$name
,
Config
::
get
(
'database.redis'
))
->
connect
();
if
(
is_null
(
$config
))
{
throw
new
\Exception
(
"Redis connection [
$name
] has not been configured."
);
}
static
::
$connections
[
$name
]
=
static
::
make
(
$name
,
$config
)
->
connect
();
}
}
return
static
::
$connection
s
[
$name
]
;
return
static
::
$connection
;
}
}
/**
/**
...
@@ -91,9 +77,9 @@ class Redis {
...
@@ -91,9 +77,9 @@ class Redis {
*/
*/
public
function
connect
()
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
}
"
);
throw
new
\Exception
(
"Error establishing Redis connection [
{
$this
->
name
}
]:
{
$error
}
-
{
$message
}
"
);
}
}
...
@@ -110,9 +96,9 @@ class Redis {
...
@@ -110,9 +96,9 @@ class Redis {
*/
*/
public
function
run
(
$method
,
$parameters
)
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 {
...
@@ -149,7 +135,7 @@ class Redis {
*/
*/
public
function
__destruct
()
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