fix: redis session

This commit is contained in:
Lakhan Samani
2023-04-03 10:26:27 +05:30
parent c8fe05eabc
commit 9a284c03ca
9 changed files with 34 additions and 31 deletions

View File

@@ -13,12 +13,6 @@ func (c *provider) SetUserSession(userId, key, token string) error {
return nil
}
// GetAllUserSessions returns all the user sessions token from the in-memory store.
func (c *provider) GetAllUserSessions(userId string) (map[string]string, error) {
data := c.sessionStore.GetAll(userId)
return data, nil
}
// GetUserSession returns value for given session token
func (c *provider) GetUserSession(userId, sessionToken string) (string, error) {
return c.sessionStore.Get(userId, sessionToken), nil

View File

@@ -31,11 +31,15 @@ func (e *EnvStore) UpdateStore(store map[string]interface{}) {
// GetStore returns the env store
func (e *EnvStore) GetStore() map[string]interface{} {
e.mutex.Lock()
defer e.mutex.Unlock()
return e.store
}
// Get returns the value of the key in evn store
func (e *EnvStore) Get(key string) interface{} {
e.mutex.Lock()
defer e.mutex.Unlock()
return e.store[key]
}

View File

@@ -5,23 +5,31 @@ import (
"sync"
)
// SessionEntry is the struct for entry stored in store
type SessionEntry struct {
Value string
ExpiresAt int64
}
// SessionStore struct to store the env variables
type SessionStore struct {
mutex sync.Mutex
store map[string]map[string]string
store map[string]map[string]*SessionEntry
}
// NewSessionStore create a new session store
func NewSessionStore() *SessionStore {
return &SessionStore{
mutex: sync.Mutex{},
store: make(map[string]map[string]string),
store: make(map[string]map[string]*SessionEntry),
}
}
// Get returns the value of the key in state store
func (s *SessionStore) Get(key, subKey string) string {
return s.store[key][subKey]
s.mutex.Lock()
defer s.mutex.Unlock()
return s.store[key][subKey].Value
}
// Set sets the value of the key in state store

View File

@@ -20,6 +20,8 @@ func NewStateStore() *StateStore {
// Get returns the value of the key in state store
func (s *StateStore) Get(key string) string {
s.mutex.Lock()
defer s.mutex.Unlock()
return s.store[key]
}