@@ -14,11 +14,7 @@ import (
14
14
)
15
15
16
16
var sessionredis * redis.Client
17
- var sessionexpire time.Duration
18
17
19
- func UpdateSessionConfig (expire time.Duration ) {
20
- sessionexpire = expire
21
- }
22
18
func UpdateSessionRedisInstance (c * redis.Client ) {
23
19
if c == nil {
24
20
slog .WarnContext (nil , "[session] redis missing,all session event will be failed" )
@@ -31,7 +27,7 @@ func UpdateSessionRedisInstance(c *redis.Client) {
31
27
32
28
// return empty means make session failed
33
29
// user should put the return data in web's Session header or metadata's Session field
34
- func MakeSession (ctx context.Context , userid , data string ) string {
30
+ func MakeSession (ctx context.Context , userid , data string , expire time. Duration ) string {
35
31
redisclient := sessionredis
36
32
if redisclient == nil {
37
33
slog .ErrorContext (ctx , "[session.make] redis missing" )
@@ -40,7 +36,7 @@ func MakeSession(ctx context.Context, userid, data string) string {
40
36
result := make ([]byte , 8 )
41
37
rand .Read (result )
42
38
sessionid := hex .EncodeToString (result )
43
- if _ , e := redisclient .SetEx (ctx , "session_" + userid , sessionid + "_" + data , sessionexpire ).Result (); e != nil {
39
+ if _ , e := redisclient .SetEx (ctx , "session_" + userid , sessionid + "_" + data , expire ).Result (); e != nil {
44
40
slog .ErrorContext (ctx , "[session.make] write session data failed" , slog .String ("userid" , userid ), slog .String ("error" , e .Error ()))
45
41
return ""
46
42
}
0 commit comments