Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aldy505/local-redis-cluster
Local Redis 6 cluster with Docker Compose
https://github.com/aldy505/local-redis-cluster
Last synced: 17 days ago
JSON representation
Local Redis 6 cluster with Docker Compose
- Host: GitHub
- URL: https://github.com/aldy505/local-redis-cluster
- Owner: aldy505
- License: mit
- Created: 2022-05-28T05:45:15.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-05-28T05:45:40.000Z (over 2 years ago)
- Last Synced: 2024-10-12T16:09:49.768Z (about 1 month ago)
- Size: 32.2 KB
- Stars: 3
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Local Redis Cluster with Docker Compose
Sets up a local Redis v6 cluster with 3 master nodes and no replica.
To add a new replica, just modify the `docker-compose.yml` file and add some more redis instance with different `ipv4_address` subnet. Then, add that new subnet into the `command` field on `redis-cluster-init`, and add the service on the `depends_on` field so the initialization service will only execute if everything's running.
To run it:
```sh
docker compose up -d
```There is no user. The password is `foobared`. Change the password to anything in `redis.conf` file.
Don't use this configuration in production.
To connect with Go:
```go
package mainimport (
"context"
"time""github.com/go-redis/redis/v8"
)func main() {
cache := redis.NewClusterClient(&redis.ClusterOptions{
Addrs: []string{"localhost:6379", "localhost:6380", "localhost:6381"},
ReadOnly: true,
Username: "",
Password: "foobared",
DialTimeout: time.Second * 30,
WriteTimeout: time.Second * 5,
ReadTimeout: time.Second * 5,
IdleTimeout: time.Second * 30,
})
defer cache.Close()ctx, cancel := context.WithTimeout(context.Background(), time.Second * 60)
defer cancel()err := cache.SetEX(ctx, "hello", "world").Err()
if err != nil {
log.Printf(err)
return
}res, err := cache.Get(ctx, "hello").Result()
if err != nil {
log.Printf(err)
return
}log.Println(res)
}
```