@@ -2,11 +2,8 @@ package session
22
33import (
44 "context"
5- "encoding/json"
65 "fmt"
76 "time"
8-
9- "github.com/PythonHacker24/linux-acl-management-backend/internal/types"
107)
118
129/* TODO: make the operations below thread safe with mutexes*/
@@ -70,23 +67,24 @@ func (m *Manager) updateSessionStatusRedis(session *Session, status Status) erro
7067 return nil
7168}
7269
73- /* save transaction results to redis */
74- func (m * Manager ) SaveTransactionRedisList (session * Session , txResult * types.Transaction , list string ) error {
75-
70+ /* increment the failed field of the session in Redis */
71+ func (m * Manager ) IncrementSessionFailedRedis (session * Session ) error {
7672 ctx := context .Background ()
73+ key := fmt .Sprintf ("session:%s" , session .ID )
7774
78- /* get the session ID */
79- sessionID := session .ID
75+ if err := m .redis .HIncrBy (ctx , key , "failed" , 1 ).Err (); err != nil {
76+ return fmt .Errorf ("failed to increment failed count in Redis: %w" , err )
77+ }
78+ return nil
79+ }
8080
81- /* create a key for Redis operation */
82- key := fmt .Sprintf ("session:%s:%s" , sessionID , list )
81+ /* increment the completed field of the session in Redis */
82+ func (m * Manager ) IncrementSessionCompletedRedis (session * Session ) error {
83+ ctx := context .Background ()
84+ key := fmt .Sprintf ("session:%s" , session .ID )
8385
84- /* marshal transaction result to JSON */
85- resultBytes , err := json .Marshal (txResult )
86- if err != nil {
87- return fmt .Errorf ("failed to marshal transaction result: %w" , err )
86+ if err := m .redis .HIncrBy (ctx , key , "completed" , 1 ).Err (); err != nil {
87+ return fmt .Errorf ("failed to increment completed count in Redis: %w" , err )
8888 }
89-
90- /* push the transaction result in the back of the list */
91- return m .redis .RPush (ctx , key , resultBytes ).Err ()
89+ return nil
9290}
0 commit comments