Переворошил файлы (опять), закинул всё в докер

This commit is contained in:
B4D_US3R 2025-04-21 23:13:46 +05:00
parent be76c08756
commit c853cfb592
11 changed files with 135 additions and 54 deletions

10
stacker/go.mod Normal file
View file

@ -0,0 +1,10 @@
module kiki/stacker
go 1.24.2
require github.com/redis/go-redis/v9 v9.7.3
require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
)

43
stacker/stacker.go Normal file
View file

@ -0,0 +1,43 @@
package stacker
import (
"context"
"github.com/redis/go-redis/v9"
)
func ConnectToRedis(addr string) redis.Client {
rdb := redis.NewClient(&redis.Options{
Addr: addr,
Password: "",
DB: 0,
})
return *rdb
}
func SetToRedis(rdb redis.Client, key string, val interface{}) error {
err := rdb.Set(context.Background(), key, val, 0).Err()
if err != nil {
return err
}
return nil
}
func CheckInRedis(rdb redis.Client, key string) (bool, error) {
_, err := rdb.Get(context.Background(), key).Result()
if err == redis.Nil {
return false, nil
} else if err != nil {
return false, err
}
return true, nil
}
func SaveRedis(rdb redis.Client) error {
err := rdb.Save(context.Background()).Err()
if err != nil {
return err
}
return nil
}