This commit is contained in:
life
2014-05-07 13:06:24 +08:00
parent fac05a7b6c
commit 476ade10e7
1085 changed files with 259628 additions and 0 deletions

View File

@ -0,0 +1,26 @@
package memcache
import (
"github.com/robfig/gomemcache/memcache"
"encoding/json"
)
func Set(key string, value map[string]string, expiration int32) {
// 把value转成byte
bytes, _ := json.Marshal(value)
if expiration == -1 {
expiration = 30 * 24 * 60 * 60 // 30天
}
client.Set(&memcache.Item{Key: key, Value: bytes, Expiration: expiration})
}
func Get(key string) map[string]string {
item, err := client.Get(key)
if err != nil {
return nil
}
m := map[string]string{}
json.Unmarshal(item.Value, &m)
return m
}