11package redis
22
33import (
4+ "context"
45 "encoding/json"
56 "sync"
67 "time"
@@ -54,17 +55,17 @@ func (s *managerStore) parseValue(value string) (map[string]string, error) {
5455 return values , nil
5556}
5657
57- func (s * managerStore ) Create (sid string , expired int64 ) (session.Store , error ) {
58+ func (s * managerStore ) Create (ctx context. Context , sid string , expired int64 ) (session.Store , error ) {
5859 values := make (map [string ]string )
59- return & store {sid : sid , cli : s .cli , expired : expired , values : values }, nil
60+ return & store {ctx : ctx , sid : sid , cli : s .cli , expired : expired , values : values }, nil
6061}
6162
62- func (s * managerStore ) Update (sid string , expired int64 ) (session.Store , error ) {
63+ func (s * managerStore ) Update (ctx context. Context , sid string , expired int64 ) (session.Store , error ) {
6364 value , err := s .getValue (sid )
6465 if err != nil {
6566 return nil , err
6667 } else if value == "" {
67- return s .Create (sid , expired )
68+ return s .Create (ctx , sid , expired )
6869 }
6970
7071 cmd := s .cli .Set (sid , value , time .Duration (expired )* time .Second )
@@ -77,15 +78,15 @@ func (s *managerStore) Update(sid string, expired int64) (session.Store, error)
7778 return nil , err
7879 }
7980
80- return & store {sid : sid , cli : s .cli , expired : expired , values : values }, nil
81+ return & store {ctx : ctx , sid : sid , cli : s .cli , expired : expired , values : values }, nil
8182}
8283
83- func (s * managerStore ) Delete (sid string ) error {
84+ func (s * managerStore ) Delete (_ context. Context , sid string ) error {
8485 cmd := s .cli .Del (sid )
8586 return cmd .Err ()
8687}
8788
88- func (s * managerStore ) Check (sid string ) (bool , error ) {
89+ func (s * managerStore ) Check (_ context. Context , sid string ) (bool , error ) {
8990 cmd := s .cli .Get (sid )
9091 if err := cmd .Err (); err != nil {
9192 if err == redis .Nil {
@@ -106,6 +107,11 @@ type store struct {
106107 expired int64
107108 values map [string ]string
108109 sync.RWMutex
110+ ctx context.Context
111+ }
112+
113+ func (s * store ) Context () context.Context {
114+ return s .ctx
109115}
110116
111117func (s * store ) SessionID () string {
0 commit comments