|
@@ -1,13 +1,18 @@
|
1
|
1
|
package auth
|
2
|
2
|
|
3
|
3
|
import (
|
|
4
|
+ "encoding/json"
|
4
|
5
|
"time"
|
5
|
6
|
|
6
|
7
|
"git.links123.net/links123.com/pkg/utils"
|
7
|
8
|
"github.com/go-redis/redis"
|
8
|
9
|
)
|
9
|
10
|
|
10
|
|
-type RedisSessionStore struct{ client *redis.Client }
|
|
11
|
+type (
|
|
12
|
+ RedisSessionStore struct{ client *redis.Client }
|
|
13
|
+
|
|
14
|
+ item map[string]interface{}
|
|
15
|
+)
|
11
|
16
|
|
12
|
17
|
func NewRedisSessionStore(address string, password string) *RedisSessionStore {
|
13
|
18
|
session := &RedisSessionStore{}
|
|
@@ -25,7 +30,7 @@ func NewRedisSessionStore(address string, password string) *RedisSessionStore {
|
25
|
30
|
|
26
|
31
|
func (rss *RedisSessionStore) StoreJwtToken(token string, uid int64, timeout int64) error {
|
27
|
32
|
k := utils.Md5(token)
|
28
|
|
- v := map[string]int64{"user_id": uid, "created": time.Now().Unix()}
|
|
33
|
+ v := item{"user_id": uid, "created": time.Now().Unix()}
|
29
|
34
|
|
30
|
35
|
return rss.client.Set(k, v, time.Duration(timeout)*time.Second).Err()
|
31
|
36
|
}
|
|
@@ -41,3 +46,7 @@ func (rss *RedisSessionStore) DeleteJwtToken(token string) bool {
|
41
|
46
|
|
42
|
47
|
return rss.client.Del(k).Val() == 1
|
43
|
48
|
}
|
|
49
|
+
|
|
50
|
+func (i item) MarshalBinary() (data []byte, err error) {
|
|
51
|
+ return json.Marshal(i)
|
|
52
|
+}
|