first commit
This commit is contained in:
24
internal/repositories/links.go
Normal file
24
internal/repositories/links.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
type LinksRepository struct {
|
||||
redis *redis.Client
|
||||
}
|
||||
|
||||
func NewLinksRepository(redis *redis.Client) *LinksRepository {
|
||||
return &LinksRepository{redis: redis}
|
||||
}
|
||||
|
||||
func (r *LinksRepository) CreateLink(shortID, original string) error {
|
||||
return r.redis.Set(context.Background(), shortID, original, 30*24*time.Hour).Err()
|
||||
}
|
||||
|
||||
func (r *LinksRepository) GetLink(shortID string) (string, error) {
|
||||
return r.redis.Get(context.Background(), shortID).Result()
|
||||
}
|
||||
Reference in New Issue
Block a user