Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
0b42e557
Commit
0b42e557
authored
Jan 09, 2014
by
Pengfei Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
align memcache operations with redis
parent
a369b15e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
10 deletions
+31
-10
memcache.go
cache/memcache.go
+31
-10
No files found.
cache/memcache.go
View file @
0b42e557
...
@@ -21,7 +21,11 @@ func NewMemCache() *MemcacheCache {
...
@@ -21,7 +21,11 @@ func NewMemCache() *MemcacheCache {
// get value from memcache.
// get value from memcache.
func
(
rc
*
MemcacheCache
)
Get
(
key
string
)
interface
{}
{
func
(
rc
*
MemcacheCache
)
Get
(
key
string
)
interface
{}
{
if
rc
.
c
==
nil
{
if
rc
.
c
==
nil
{
rc
.
c
=
rc
.
connectInit
()
var
err
error
rc
.
c
,
err
=
rc
.
connectInit
()
if
err
!=
nil
{
return
err
}
}
}
v
,
err
:=
rc
.
c
.
Get
(
key
)
v
,
err
:=
rc
.
c
.
Get
(
key
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -39,7 +43,11 @@ func (rc *MemcacheCache) Get(key string) interface{} {
...
@@ -39,7 +43,11 @@ func (rc *MemcacheCache) Get(key string) interface{} {
// put value to memcache. only support string.
// put value to memcache. only support string.
func
(
rc
*
MemcacheCache
)
Put
(
key
string
,
val
interface
{},
timeout
int64
)
error
{
func
(
rc
*
MemcacheCache
)
Put
(
key
string
,
val
interface
{},
timeout
int64
)
error
{
if
rc
.
c
==
nil
{
if
rc
.
c
==
nil
{
rc
.
c
=
rc
.
connectInit
()
var
err
error
rc
.
c
,
err
=
rc
.
connectInit
()
if
err
!=
nil
{
return
err
}
}
}
v
,
ok
:=
val
.
(
string
)
v
,
ok
:=
val
.
(
string
)
if
!
ok
{
if
!
ok
{
...
@@ -55,7 +63,11 @@ func (rc *MemcacheCache) Put(key string, val interface{}, timeout int64) error {
...
@@ -55,7 +63,11 @@ func (rc *MemcacheCache) Put(key string, val interface{}, timeout int64) error {
// delete value in memcache.
// delete value in memcache.
func
(
rc
*
MemcacheCache
)
Delete
(
key
string
)
error
{
func
(
rc
*
MemcacheCache
)
Delete
(
key
string
)
error
{
if
rc
.
c
==
nil
{
if
rc
.
c
==
nil
{
rc
.
c
=
rc
.
connectInit
()
var
err
error
rc
.
c
,
err
=
rc
.
connectInit
()
if
err
!=
nil
{
return
err
}
}
}
_
,
err
:=
rc
.
c
.
Delete
(
key
)
_
,
err
:=
rc
.
c
.
Delete
(
key
)
return
err
return
err
...
@@ -76,7 +88,11 @@ func (rc *MemcacheCache) Decr(key string) error {
...
@@ -76,7 +88,11 @@ func (rc *MemcacheCache) Decr(key string) error {
// check value exists in memcache.
// check value exists in memcache.
func
(
rc
*
MemcacheCache
)
IsExist
(
key
string
)
bool
{
func
(
rc
*
MemcacheCache
)
IsExist
(
key
string
)
bool
{
if
rc
.
c
==
nil
{
if
rc
.
c
==
nil
{
rc
.
c
=
rc
.
connectInit
()
var
err
error
rc
.
c
,
err
=
rc
.
connectInit
()
if
err
!=
nil
{
return
false
}
}
}
v
,
err
:=
rc
.
c
.
Get
(
key
)
v
,
err
:=
rc
.
c
.
Get
(
key
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -93,7 +109,11 @@ func (rc *MemcacheCache) IsExist(key string) bool {
...
@@ -93,7 +109,11 @@ func (rc *MemcacheCache) IsExist(key string) bool {
// clear all cached in memcache.
// clear all cached in memcache.
func
(
rc
*
MemcacheCache
)
ClearAll
()
error
{
func
(
rc
*
MemcacheCache
)
ClearAll
()
error
{
if
rc
.
c
==
nil
{
if
rc
.
c
==
nil
{
rc
.
c
=
rc
.
connectInit
()
var
err
error
rc
.
c
,
err
=
rc
.
connectInit
()
if
err
!=
nil
{
return
err
}
}
}
err
:=
rc
.
c
.
FlushAll
()
err
:=
rc
.
c
.
FlushAll
()
return
err
return
err
...
@@ -109,20 +129,21 @@ func (rc *MemcacheCache) StartAndGC(config string) error {
...
@@ -109,20 +129,21 @@ func (rc *MemcacheCache) StartAndGC(config string) error {
return
errors
.
New
(
"config has no conn key"
)
return
errors
.
New
(
"config has no conn key"
)
}
}
rc
.
conninfo
=
cf
[
"conn"
]
rc
.
conninfo
=
cf
[
"conn"
]
rc
.
c
=
rc
.
connectInit
()
var
err
error
if
rc
.
c
==
nil
{
rc
.
c
,
err
=
rc
.
connectInit
()
if
err
!=
nil
{
return
errors
.
New
(
"dial tcp conn error"
)
return
errors
.
New
(
"dial tcp conn error"
)
}
}
return
nil
return
nil
}
}
// connect to memcache and keep the connection.
// connect to memcache and keep the connection.
func
(
rc
*
MemcacheCache
)
connectInit
()
*
memcache
.
Connection
{
func
(
rc
*
MemcacheCache
)
connectInit
()
(
*
memcache
.
Connection
,
error
)
{
c
,
err
:=
memcache
.
Connect
(
rc
.
conninfo
)
c
,
err
:=
memcache
.
Connect
(
rc
.
conninfo
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
return
nil
,
err
}
}
return
c
return
c
,
nil
}
}
func
init
()
{
func
init
()
{
...
...
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