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
7df74c0a
Commit
7df74c0a
authored
Aug 30, 2016
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix #1521
parent
1e1e9002
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
10 deletions
+11
-10
memcache.go
cache/memcache/memcache.go
+11
-10
No files found.
cache/memcache/memcache.go
View file @
7df74c0a
...
...
@@ -33,12 +33,10 @@ import (
"encoding/json"
"errors"
"strings"
"github.com/bradfitz/gomemcache/memcache"
"time"
"github.com/astaxie/beego/cache"
"github.com/bradfitz/gomemcache/memcache"
)
// Cache Memcache adapter.
...
...
@@ -60,7 +58,7 @@ func (rc *Cache) Get(key string) interface{} {
}
}
if
item
,
err
:=
rc
.
conn
.
Get
(
key
);
err
==
nil
{
return
string
(
item
.
Value
)
return
item
.
Value
}
return
nil
}
...
...
@@ -80,7 +78,7 @@ func (rc *Cache) GetMulti(keys []string) []interface{} {
mv
,
err
:=
rc
.
conn
.
GetMulti
(
keys
)
if
err
==
nil
{
for
_
,
v
:=
range
mv
{
rv
=
append
(
rv
,
string
(
v
.
Value
)
)
rv
=
append
(
rv
,
v
.
Value
)
}
return
rv
}
...
...
@@ -90,18 +88,21 @@ func (rc *Cache) GetMulti(keys []string) []interface{} {
return
rv
}
// Put put value to memcache.
only support string.
// Put put value to memcache.
func
(
rc
*
Cache
)
Put
(
key
string
,
val
interface
{},
timeout
time
.
Duration
)
error
{
if
rc
.
conn
==
nil
{
if
err
:=
rc
.
connectInit
();
err
!=
nil
{
return
err
}
}
v
,
ok
:=
val
.
(
string
)
if
!
ok
{
return
errors
.
New
(
"val must string"
)
item
:=
memcache
.
Item
{
Key
:
key
,
Expiration
:
int32
(
timeout
/
time
.
Second
)}
if
v
,
ok
:=
val
.
([]
byte
);
ok
{
item
.
Value
=
v
}
else
if
str
,
ok
:=
val
.
(
string
);
ok
{
item
.
Value
=
[]
byte
(
str
)
}
else
{
return
errors
.
New
(
"val only support string and []byte"
)
}
item
:=
memcache
.
Item
{
Key
:
key
,
Value
:
[]
byte
(
v
),
Expiration
:
int32
(
timeout
/
time
.
Second
)}
return
rc
.
conn
.
Set
(
&
item
)
}
...
...
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