11package redis
22
33import (
4+ "fmt"
45 "strconv"
56
67 "github.com/authorizerdev/authorizer/server/constants"
@@ -16,28 +17,17 @@ var (
1617
1718// SetUserSession sets the user session for given user identifier in form recipe:user_id
1819func (c * provider ) SetUserSession (userId , key , token string ) error {
19- err := c .store .HSet (c .ctx , userId , key , token ).Err ()
20+ err := c .store .Set (c .ctx , fmt . Sprintf ( "%s:%s" , userId , key ) , token , 0 ).Err ()
2021 if err != nil {
21- log .Debug ("Error saving to redis: " , err )
22+ log .Debug ("Error saving user session to redis: " , err )
2223 return err
2324 }
2425 return nil
2526}
2627
27- // GetAllUserSessions returns all the user session token from the redis store.
28- func (c * provider ) GetAllUserSessions (userID string ) (map [string ]string , error ) {
29- data , err := c .store .HGetAll (c .ctx , userID ).Result ()
30- if err != nil {
31- log .Debug ("error getting all user sessions from redis store: " , err )
32- return nil , err
33- }
34-
35- return data , nil
36- }
37-
3828// GetUserSession returns the user session from redis store.
3929func (c * provider ) GetUserSession (userId , key string ) (string , error ) {
40- data , err := c .store .HGet (c .ctx , userId , key ).Result ()
30+ data , err := c .store .Get (c .ctx , fmt . Sprintf ( "%s:%s" , userId , key ) ).Result ()
4131 if err != nil {
4232 return "" , err
4333 }
@@ -46,15 +36,15 @@ func (c *provider) GetUserSession(userId, key string) (string, error) {
4636
4737// DeleteUserSession deletes the user session from redis store.
4838func (c * provider ) DeleteUserSession (userId , key string ) error {
49- if err := c .store .HDel (c .ctx , userId , constants .TokenTypeSessionToken + "_" + key ).Err (); err != nil {
39+ if err := c .store .Del (c .ctx , fmt . Sprintf ( "%s:%s" , userId , constants .TokenTypeSessionToken + "_" + key ) ).Err (); err != nil {
5040 log .Debug ("Error deleting user session from redis: " , err )
5141 return err
5242 }
53- if err := c .store .HDel (c .ctx , userId , constants .TokenTypeAccessToken + "_" + key ).Err (); err != nil {
43+ if err := c .store .Del (c .ctx , fmt . Sprintf ( "%s:%s" , userId , constants .TokenTypeAccessToken + "_" + key ) ).Err (); err != nil {
5444 log .Debug ("Error deleting user session from redis: " , err )
5545 return err
5646 }
57- if err := c .store .HDel (c .ctx , userId , constants .TokenTypeRefreshToken + "_" + key ).Err (); err != nil {
47+ if err := c .store .Del (c .ctx , fmt . Sprintf ( "%s:%s" , userId , constants .TokenTypeRefreshToken + "_" + key ) ).Err (); err != nil {
5848 log .Debug ("Error deleting user session from redis: " , err )
5949 return err
6050 }
0 commit comments