create redis session
This commit is contained in:
@@ -41,7 +41,25 @@ func NewRedisStore() *RedisStore {
|
|||||||
return store
|
return store
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// return rdb.Set(ctx, key, data, 0).Err()
|
||||||
|
|
||||||
func (m *RedisStore) Create(sessionID string, session *SessionData) (err error) {
|
func (m *RedisStore) Create(sessionID string, session *SessionData) (err error) {
|
||||||
|
hashedSession := hashSession(sessionID)
|
||||||
|
|
||||||
|
data, err := json.Marshal(*session)
|
||||||
|
if err != nil {
|
||||||
|
return ErrSessionBackend
|
||||||
|
}
|
||||||
|
|
||||||
|
created, err := m.client.SetNX(m.ctx, hashedSession, data, 0).Result()
|
||||||
|
if err != nil {
|
||||||
|
logging.Error(err.Error())
|
||||||
|
return ErrSessionBackend
|
||||||
|
}
|
||||||
|
|
||||||
|
if !created {
|
||||||
|
return ErrSessionAlreadyExists
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (m *RedisStore) Get(sessionID string) (*SessionData, error) {
|
func (m *RedisStore) Get(sessionID string) (*SessionData, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user