Repository Pattern Redis Example
This is a simple example project that demonstrates how to connect to a Redis database using Go and the go-redis
library.
Prerequisites
Before running this project, make sure you have the following prerequisites:
Getting Started
Follow the steps below to set up and run the project:
- Clone the repository:
$ git clone https://github.com/lucasgrvarela/go-redis-example.git
- Change into the project directory:
$ cd go-redis-example
- Start a Redis server using Docker:
$ docker run -d -p 6379:6379 --name redis-server redis
- Run the Go application:
$ go run *.go
Key set successfully!
Key: 'mykey' retrieved, value: 'myvalue'
- Test manually everything worked as expected:
$ docker exec -it redis-server bash
$ redis-cli # run inside the container
127.0.0.1:6379> GET mykey
"myvalue"
Configuration
By default, the Go application connects to Redis running on localhost:6379. If your Redis server is running on a different address or port, you can modify the main.go file and update the Redis server address in the NewRedisClient function.
Contributing
Contributions are welcome! If you find any issues with the project or want to extend it further, feel free to open an issue or submit a pull request.