store

package
v0.0.0-...-cc299b8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Storage

type Storage struct {
	Pool      *redis.Pool
	IDChannel chan int
	LastID    int
}

Storage keeps pool of connections for redis, number of saved URLs and channel required for generation of short aliases for new incoming URLs.

func New

func New(redisURL string, db int) (*Storage, error)

New returns an instance of Storage.

func (*Storage) Close

func (s *Storage) Close()

Close closes all connections to Redis, releasing all resources.

func (*Storage) Longer

func (s *Storage) Longer(short []byte) ([]byte, error)

Longer searches the original URL in Redis by given short alias.

func (*Storage) SaveFull

func (s *Storage) SaveFull(longURL []byte) ([]byte, error)

SaveFull generates a unique short alias for the given URL, saves the match between this alias and the given URL into Redis and returns alias.

func (*Storage) Shorter

func (s *Storage) Shorter(longURL []byte) ([]byte, error)

Shorter checks if the given URL has a short version saved earlier. If not, it saves it into Redis and returns a short alias for the given URL.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL