rediska
This commit is contained in:
16
nzx_tmpmail/app.log
Normal file
16
nzx_tmpmail/app.log
Normal file
@@ -0,0 +1,16 @@
|
||||
[nzx_tmpmail] 2026/04/29 08:31:37 hey nigga
|
||||
[nzx_tmpmail] 2026/04/29 11:29:03 hey nigga
|
||||
[nzx_tmpmail] 2026/04/29 11:29:03 redis init
|
||||
[nzx_tmpmail] 2026/04/29 11:29:03 redis test success with val = REDISKANAHUI
|
||||
[nzx_tmpmail] 2026/04/29 11:36:30 hey nigga
|
||||
[nzx_tmpmail] 2026/04/29 11:36:30 redis init
|
||||
[nzx_tmpmail] 2026/04/29 11:36:30 redis test success with val = REDISKANAHUI
|
||||
[nzx_tmpmail] 2026/04/29 11:36:42 hey nigga
|
||||
[nzx_tmpmail] 2026/04/29 11:36:42 redis init
|
||||
[nzx_tmpmail] 2026/04/29 11:36:42 redis test success with val = REDISKANAHUI
|
||||
[nzx_tmpmail] 2026/04/29 11:36:49 hey nigga
|
||||
[nzx_tmpmail] 2026/04/29 11:36:49 redis init
|
||||
[nzx_tmpmail] 2026/04/29 11:36:49 [critical] redis test failed on rdb.Get with error: redis: nil
|
||||
[nzx_tmpmail] 2026/04/29 11:37:01 hey nigga
|
||||
[nzx_tmpmail] 2026/04/29 11:37:01 redis init
|
||||
[nzx_tmpmail] 2026/04/29 11:37:01 redis test success with val = REDISKANAHUI
|
||||
@@ -1,3 +1,9 @@
|
||||
module git.uwushka.cc/nzx056/nzx056/nzx_tmpmail
|
||||
|
||||
go 1.25.4
|
||||
|
||||
require (
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/redis/go-redis/v9 v9.19.0 // indirect
|
||||
go.uber.org/atomic v1.11.0 // indirect
|
||||
)
|
||||
|
||||
6
nzx_tmpmail/go.sum
Normal file
6
nzx_tmpmail/go.sum
Normal file
@@ -0,0 +1,6 @@
|
||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/redis/go-redis/v9 v9.19.0 h1:XPVaaPSnG6RhYf7p+rmSa9zZfeVAnWsH5h3lxthOm/k=
|
||||
github.com/redis/go-redis/v9 v9.19.0/go.mod h1:v/M13XI1PVCDcm01VtPFOADfZtHf8YW3baQf57KlIkA=
|
||||
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
|
||||
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
|
||||
@@ -1,5 +1,9 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
import (
|
||||
"git.uwushka.cc/nzx056/nzx056/nzx_tmpmail/storage"
|
||||
)
|
||||
|
||||
func main() {
|
||||
storage.RedisInit()
|
||||
}
|
||||
|
||||
@@ -1 +1,80 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"git.uwushka.cc/nzx056/nzx056/nzx_tmpmail/loggingshit"
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
var rdb *redis.Client
|
||||
var ctx = context.Background()
|
||||
|
||||
type Mail struct {
|
||||
From string
|
||||
To string
|
||||
RawData string
|
||||
}
|
||||
|
||||
type MailClient struct {
|
||||
Name string
|
||||
Mail []Mail
|
||||
}
|
||||
|
||||
func GetMailClient(ctx context.Context, id string) (MailClient, error) {
|
||||
var m MailClient
|
||||
b, err := rdb.Get(ctx, "mailclient:"+id).Bytes()
|
||||
if err != nil {
|
||||
return m, err
|
||||
}
|
||||
err = json.Unmarshal(b, &m)
|
||||
|
||||
return m, err
|
||||
}
|
||||
|
||||
func NewMail(ctx context.Context, rcp string, from string, rawdata string) error {
|
||||
m, err := GetMailClient(ctx, rcp)
|
||||
if err != nil {
|
||||
m = MailClient{
|
||||
Name: rcp,
|
||||
Mail: []Mail{},
|
||||
}
|
||||
}
|
||||
|
||||
m.Mail = append(m.Mail, Mail{
|
||||
From: from,
|
||||
To: rcp,
|
||||
RawData: rawdata,
|
||||
})
|
||||
|
||||
b, err := json.Marshal(m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := rdb.Set(ctx, "mailclient:"+rcp, b, time.Minute*10).Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func RedisInit() {
|
||||
rdb = redis.NewClient(&redis.Options{
|
||||
Addr: "localhost:6379",
|
||||
Password: "",
|
||||
DB: 0,
|
||||
})
|
||||
|
||||
if err := rdb.Ping(ctx).Err(); err != nil {
|
||||
loggingshit.Log("redis failed on rdb.Ping() with error %v", 1, err)
|
||||
}
|
||||
|
||||
loggingshit.Log("redis init", 1)
|
||||
}
|
||||
|
||||
func Client() *redis.Client {
|
||||
return rdb
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user