Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
X Lib
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
XLibs
X Lib
Commits
75426635
Commit
75426635
authored
Sep 18, 2016
by
Alex Ne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Думал заюзать Memcached а фиг там.
parent
1954f05c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
135 additions
and
0 deletions
+135
-0
Memcached.php
Cache/Memcached.php
+55
-0
MemcachedCredetional.php
Cache/MemcachedCredetional.php
+80
-0
No files found.
Cache/Memcached.php
0 → 100644
View file @
75426635
<?php
namespace
X\Cache
;
class
Memcached
{
/**
* @var mixed
*/
protected
$prefix
;
/**
* @var mixed
*/
public
$link
=
false
;
/**
* @param $prefix
* @param $host
* @param $port
*/
public
function
__construct
(
MemcachedCredetional
$Credetional
)
{
if
(
class_exists
(
"\Memcached"
))
{
$this
->
prefix
=
$Credetional
->
get_prefix
();
$this
->
link
=
new
\Memcached
(
$this
->
prefix
);
echo
"con"
;
$this
->
link
->
addServers
(
$Credetional
->
get_servers
());
}
}
/**
* @param $key
* @param $value
* @param $expire
*/
public
function
set
(
$key
,
$value
,
$expire
=
240
)
{
if
(
!
$this
->
link
)
{
return
$this
->
link
;
}
$key
=
$this
->
prefix
.
$key
;
return
$this
->
link
->
set
(
$key
,
$value
,
$expire
);
}
/**
* @param $key
*/
public
function
get
(
$key
)
{
if
(
!
$this
->
link
)
{
return
$this
->
link
;
}
$key
=
$this
->
prefix
.
$key
;
return
$this
->
link
->
get
(
$key
);
}
}
?>
\ No newline at end of file
Cache/MemcachedCredetional.php
0 → 100644
View file @
75426635
<?php
namespace
X\Cache
;
use
\X\ETrace\System
as
ESys
;
class
MemcachedCredetional_ConfigError
extends
ESys
{}
class
MemcachedCredetional_ConfigTypeError
extends
ESys
{}
class
MemcachedCredetional
{
/**
* @var mixed
*/
protected
$prefix
,
$servers
=
[];
/**
* @param $prefix
* @param array $servers
*/
public
function
__construct
(
$prefix
=
'x_lib'
,
$servers
=
[
"localhost"
,
11211
,
100
])
{
$this
->
prefix
=
$prefix
;
if
(
isset
(
$servers
[
0
]))
{
$type
=
gettype
(
$servers
[
0
]);
switch
(
$type
)
{
case
'string'
:
$host
=
(
isset
(
$servers
[
0
]))
?
$servers
[
0
]
:
"localhost"
;
$port
=
(
isset
(
$servers
[
1
]))
?
$servers
[
1
]
:
11211
;
$weight
=
(
isset
(
$servers
[
2
]))
?
$servers
[
2
]
:
100
;
$this
->
addServer
(
$host
,
$port
,
$weight
);
break
;
case
'array'
:
if
(
is_string
(
$servers
[
0
][
0
]))
{
}
else
{
throw
new
MemcachedCredetional_ConfigTypeError
(
"Unknow type"
,
1
,
$servers
);
}
break
;
default
:
throw
new
MemcachedCredetional_ConfigTypeError
(
"Unknow type"
,
1
,
$servers
);
break
;
}
}
}
/**
* @param $value
*/
public
function
addServer
(
$host
,
$port
=
11211
,
$weight
=
100
)
{
$this
->
servers
[]
=
[
$host
,
$port
,
$weight
];
}
/**
* @param $value
*/
public
function
addServers
(
$servers
)
{
if
(
is_array
(
$servers
)
&&
count
(
$servers
)
>
0
)
{
foreach
(
$servers
as
$server
)
{
if
(
is_string
(
$server
[
0
]))
{
$host
=
(
isset
(
$server
[
0
]))
?
$server
[
0
]
:
"localhost"
;
$port
=
(
isset
(
$server
[
1
]))
?
$server
[
1
]
:
11211
;
$weight
=
(
isset
(
$server
[
2
]))
?
$server
[
2
]
:
100
;
$this
->
addServer
(
$host
,
$port
,
$weight
);
}
else
{
throw
new
MemcachedCredetional_ConfigTypeError
(
"Unknow type"
,
1
,
$servers
);
}
}
}
}
/**
* @return mixed
*/
public
function
get_prefix
()
{
return
$this
->
prefix
;
}
/**
* @return mixed
*/
public
function
get_servers
()
{
return
$this
->
servers
;
}
}
?>
\ 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