package main import ( "context" "github.com/redis/go-redis/v9" "log" "time" ) var ctx = context.Background() func connectDB() *redis.Client { localDb := redis.NewClient(&redis.Options{ Addr: currentConfig.redisAddr, Username: currentConfig.redisUser, Password: currentConfig.redisPassword, DB: currentConfig.redisDB, }) return localDb } func insertPaste(key string, content string, secret string, ttl time.Duration) { type dbSchema struct { content string secret string } hash := dbSchema{ content: content, secret: secret, } err := db.HSet(ctx, key, "content", hash.content) if err != nil { log.Println(err) } err = db.HSet(ctx, key, "secret", hash.secret) if ttl > -1 { db.Do(ctx, key, ttl) } } func getContent(key string) string { content := db.HGet(ctx, key, "content").Val() return content } func deleteContent(key string) { err := db.Del(ctx, key) if err != nil { log.Println(err) } }