Skip to content

Commit bef3ce7

Browse files
authored
Create redis.go
1 parent 2b656bb commit bef3ce7

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

redis.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"time"
7+
8+
"github.com/go-redis/redis/v8"
9+
)
10+
11+
func sendMetadataToRedis(config *Config, username, content, sourceIP string) error {
12+
if config.General.Redis.IP == "" || config.General.Redis.Port == 0 {
13+
return nil
14+
}
15+
16+
rdb := redis.NewClient(&redis.Options{
17+
Addr: fmt.Sprintf("%s:%d", config.General.Redis.IP, config.General.Redis.Port),
18+
})
19+
ctx := context.Background()
20+
loginTime := time.Now().Format(time.RFC3339)
21+
data := fmt.Sprintf("Username: %s, Content: %s, SourceIP: %s, LoginTime: %s", username, content, sourceIP, loginTime)
22+
return rdb.Set(ctx, "session_metadata", data, 0).Err()
23+
}

0 commit comments

Comments
 (0)