Init commit, base struct and redis connection
This commit is contained in:
35
manager/redis.go
Normal file
35
manager/redis.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package manager
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
func NewRedisClient() *redis.Client {
|
||||
addr := os.Getenv("REDIS_ADDR")
|
||||
if addr == "" {
|
||||
addr = "redis:6379"
|
||||
}
|
||||
|
||||
password := os.Getenv("REDIS_PASSWORD")
|
||||
|
||||
return redis.NewClient(&redis.Options{
|
||||
Addr: addr,
|
||||
Password: password,
|
||||
DB: 0,
|
||||
})
|
||||
}
|
||||
|
||||
func GetWebhooks(ctx context.Context, client *redis.Client) ([]string, error) {
|
||||
return client.LRange(ctx, "webhooks", 0, -1).Result()
|
||||
}
|
||||
|
||||
func CreateWebhook(ctx context.Context, client *redis.Client, webhook string) error {
|
||||
return client.LPush(ctx, "webhooks", webhook).Err()
|
||||
}
|
||||
|
||||
func DeleteWebhook(ctx context.Context, client *redis.Client, webhook string) error {
|
||||
return client.LRem(ctx, "webhooks", 0, webhook).Err()
|
||||
}
|
||||
Reference in New Issue
Block a user