26-go-caching-memcached

command module
v0.0.0-...-a32095e Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: MIT Imports: 12 Imported by: 0

README

Caching in Go: memcached

Requirements

  1. Go 1.15
  2. direnv: for sanboxing the required tools used by this project.
  3. PostgreSQL: either a remote instance, local binary or docker container.
  4. Memcached: either a remote instance, local binary or docker container.
  5. Load testing data

Running

Download the required packages:

go mod download

Then you can run server.go with the PostgreSQL and memcached configuration:

DATABASE_URL=postgres://user:password@localhost:5432/dbname?sslmode=disable \
MEMCACHED=localhost:11211 \
  go run .
PostgreSQL
Using Docker
docker run \
  -d \
  -e POSTGRES_HOST_AUTH_METHOD=trust \
  -e POSTGRES_USER=user \
  -e POSTGRES_PASSWORD=password \
  -e POSTGRES_DB=dbname \
  -p 5432:5432 \
  postgres:12.5-alpine
Migrations

Make sure the migrate tool is installed:

go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate

Then, assuming you used docker, you can run:

migrate -path db/migrations/ -database "postgres://user:password@localhost:5432/dbname?sslmode=disable" up
Memcached
docker run \
  -d \
  -p 11211:11211 \
  memcached:1.6.9-alpine
Load testing data

You can use the tool I build during my Implementing Complex Pipelines in Go series, install it using:

go install github.com/MarioCarrion/complex-pipelines/part5

Then run it using:

DATABASE_URL="postgres://user:password@localhost:5432/dbname?sslmode=disable" part5

Sadly, at the moment this tool does not provide any progress feedback; but it should finish after a couple of minutes.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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