36 lines
760 B
Go
36 lines
760 B
Go
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()
|
|
}
|