mirror of
https://github.com/astaxie/beego.git
synced 2025-06-11 08:30:40 +00:00
fix #1530
This commit is contained in:
5
cache/memcache/memcache.go
vendored
5
cache/memcache/memcache.go
vendored
@ -37,6 +37,7 @@ import (
|
||||
"github.com/bradfitz/gomemcache/memcache"
|
||||
|
||||
"github.com/astaxie/beego/cache"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Cache Memcache adapter.
|
||||
@ -89,7 +90,7 @@ func (rc *Cache) GetMulti(keys []string) []interface{} {
|
||||
}
|
||||
|
||||
// Put put value to memcache. only support string.
|
||||
func (rc *Cache) Put(key string, val interface{}, timeout int64) error {
|
||||
func (rc *Cache) Put(key string, val interface{}, timeout time.Duration) error {
|
||||
if rc.conn == nil {
|
||||
if err := rc.connectInit(); err != nil {
|
||||
return err
|
||||
@ -99,7 +100,7 @@ func (rc *Cache) Put(key string, val interface{}, timeout int64) error {
|
||||
if !ok {
|
||||
return errors.New("val must string")
|
||||
}
|
||||
item := memcache.Item{Key: key, Value: []byte(v), Expiration: int32(timeout)}
|
||||
item := memcache.Item{Key: key, Value: []byte(v), Expiration: int32(timeout.Seconds())}
|
||||
return rc.conn.Set(&item)
|
||||
}
|
||||
|
||||
|
9
cache/memcache/memcache_test.go
vendored
9
cache/memcache/memcache_test.go
vendored
@ -28,7 +28,8 @@ func TestMemcacheCache(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error("init err")
|
||||
}
|
||||
if err = bm.Put("astaxie", "1", 10); err != nil {
|
||||
timeoutDuration := time.Second * 10
|
||||
if err = bm.Put("astaxie", "1", timeoutDuration); err != nil {
|
||||
t.Error("set Error", err)
|
||||
}
|
||||
if !bm.IsExist("astaxie") {
|
||||
@ -40,7 +41,7 @@ func TestMemcacheCache(t *testing.T) {
|
||||
if bm.IsExist("astaxie") {
|
||||
t.Error("check err")
|
||||
}
|
||||
if err = bm.Put("astaxie", "1", 10); err != nil {
|
||||
if err = bm.Put("astaxie", "1", timeoutDuration); err != nil {
|
||||
t.Error("set Error", err)
|
||||
}
|
||||
|
||||
@ -69,7 +70,7 @@ func TestMemcacheCache(t *testing.T) {
|
||||
}
|
||||
|
||||
//test string
|
||||
if err = bm.Put("astaxie", "author", 10); err != nil {
|
||||
if err = bm.Put("astaxie", "author", timeoutDuration); err != nil {
|
||||
t.Error("set Error", err)
|
||||
}
|
||||
if !bm.IsExist("astaxie") {
|
||||
@ -81,7 +82,7 @@ func TestMemcacheCache(t *testing.T) {
|
||||
}
|
||||
|
||||
//test GetMulti
|
||||
if err = bm.Put("astaxie1", "author1", 10); err != nil {
|
||||
if err = bm.Put("astaxie1", "author1", timeoutDuration); err != nil {
|
||||
t.Error("set Error", err)
|
||||
}
|
||||
if !bm.IsExist("astaxie1") {
|
||||
|
Reference in New Issue
Block a user