Skip to content

Commit 5368bb6

Browse files
Impleted save transactions results to redis function
1 parent 30128d3 commit 5368bb6

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

internal/session/redisInteract.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ package session
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
67
"time"
8+
9+
"github.com/PythonHacker24/linux-acl-management-backend/internal/transprocessor"
710
)
811

912
/* we make use of Redis hashes for this application */
@@ -85,3 +88,21 @@ func (m *Manager) updateSessionStatus(username string, status Status) error {
8588

8689
return nil
8790
}
91+
92+
/* save transaction results to redis */
93+
func (m *Manager) saveTransactionResults(sessionID string, txResult transprocessor.Transaction) error {
94+
95+
ctx := context.Background()
96+
97+
/* create a key for Redis operation */
98+
key := fmt.Sprintf("session:%s:txresults", sessionID)
99+
100+
/* marshal transaction result to JSON */
101+
resultBytes, err := json.Marshal(txResult)
102+
if err != nil {
103+
return fmt.Errorf("failed to marshal transaction result: %w", err)
104+
}
105+
106+
/* push the transaction result in the back of the list */
107+
return m.redis.RPush(ctx, key, resultBytes).Err()
108+
}

0 commit comments

Comments
 (0)