11package tgw
22
33import (
4+ "github.com/icattlecoder/mcClient"
45 "encoding/json"
56 "errors"
67 "github.com/bradfitz/gomemcache/memcache"
78)
89
910//==================================================
1011type memcachedSessionStore struct {
11- client * memcache. Client
12+ client mcClient. MC
1213}
1314
1415func NewMemcachedSessionStore (mc ... string ) * memcachedSessionStore {
15-
16- return & memcachedSessionStore {client : memcache .New (mc ... )}
16+ return & memcachedSessionStore {client :mcClient .NewGobMCClient ("session" , mc ... )}
1717}
1818
1919func memcache_key (id , key string ) string {
@@ -27,32 +27,22 @@ func (s *memcachedSessionStore) Clear(id string, key string) {
2727
2828func (s * memcachedSessionStore ) Get (id string , key string , val interface {}) (err error ) {
2929
30- item , err := s .client .Get (memcache_key (id , key ))
31- if err != nil {
32- return
33- }
34- if len (item .Value ) == 0 {
35- err = errors .New ("memcache miss cache,key:" + memcache_key (id , key ))
36- return
37- }
38- err = json .Unmarshal (item .Value , & val )
39- if err != nil {
40- return
41- }
30+ err = s .client .Get (memcache_key (id , key ),val )
31+ return
32+ }
33+
34+ func (s * memcachedSessionStore ) GetString (id string , key string ) (val string , err error ) {
35+
36+ val , err = s .client .GetString (memcache_key (id , key ))
4237 return
4338}
4439
4540func (s * memcachedSessionStore ) Set (id string , key string , val interface {}) (err error ) {
4641
47- bval , err := json . Marshal ( val )
48- if err != nil {
49- return
50- }
42+ return s . client . Set ( memcache_key ( id , key ), val )
43+ }
44+
45+ func ( s * memcachedSessionStore ) SetString ( id string , key string , val string ) ( err error ) {
5146
52- item := & memcache.Item {
53- Key : memcache_key (id , key ),
54- Value : bval ,
55- }
56- err = s .client .Set (item )
57- return
47+ return s .client .SetString (memcache_key (id ,key ), val )
5848}
0 commit comments