feat: separate redis addr and port from config
This commit is contained in:
parent
596a7219cf
commit
a9106ed363
@ -7,7 +7,8 @@ WebServer:
|
||||
Redis:
|
||||
Db: ${REDIS_DB}
|
||||
QueueDb: ${REDIS_QUEUE_DB}
|
||||
Address: ${REDIS_ADDRESS_PORT}
|
||||
Address: ${REDIS_ADDRESS}
|
||||
Port: ${REDIS_PORT}
|
||||
Password: ${REDIS_PASSWORD}
|
||||
|
||||
Database:
|
||||
|
@ -7,7 +7,7 @@ services:
|
||||
interval: 5s
|
||||
command: web
|
||||
environment:
|
||||
- REDIS_ADDRESS_PORT=cache:6379
|
||||
- REDIS_ADDRESS=cache
|
||||
- DATABASE_HOST=db
|
||||
- DATABASE_USER=dev
|
||||
- DATABASE_PASSWORD=password
|
||||
@ -44,7 +44,7 @@ services:
|
||||
devices:
|
||||
- "/dev/fuse"
|
||||
environment:
|
||||
- REDIS_ADDRESS_PORT=cache:6379
|
||||
- REDIS_ADDRESS=cache
|
||||
- STORAGE_ENDPOINT=storage:9000
|
||||
- STORAGE_ACCESS_KEY=access_key
|
||||
- STORAGE_SECRET_KEY=secret_key
|
||||
|
@ -41,7 +41,8 @@ check_env "WEB_SERVER_JWT_EXPIRE_HOUR" 12 false
|
||||
|
||||
check_env "REDIS_DB" 0 false
|
||||
check_env "REDIS_QUEUE_DB" 1 false
|
||||
check_env "REDIS_ADDRESS_PORT" "redis:6379" true
|
||||
check_env "REDIS_ADDRESS" "redis" true
|
||||
check_env "REDIS_PORT" 6379 false
|
||||
check_env "REDIS_PASSWORD" "" true
|
||||
|
||||
check_env "DATABASE_HOST" "postgres" true
|
||||
|
@ -33,14 +33,7 @@ func (h *handler) Create(c *gin.Context) {
|
||||
}
|
||||
|
||||
uid := claim.(*model.Claim).UID
|
||||
|
||||
role := claim.(*model.Claim).Role
|
||||
req := new(createRequest)
|
||||
|
||||
if err := c.ShouldBind(req); err != nil {
|
||||
e.Pong(c, e.InvalidParameter, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// guest can not submit
|
||||
if role < model.RoleGeneral {
|
||||
@ -48,6 +41,12 @@ func (h *handler) Create(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
req := new(createRequest)
|
||||
if err := c.ShouldBind(req); err != nil {
|
||||
e.Pong(c, e.InvalidParameter, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
createData := &submission.CreateData{
|
||||
ProblemID: req.Pid,
|
||||
UserID: uid,
|
||||
|
@ -1,6 +1,7 @@
|
||||
package runner
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.0x7f.app/WOJ/woj-server/internal/api/runner"
|
||||
"git.0x7f.app/WOJ/woj-server/internal/misc/config"
|
||||
"git.0x7f.app/WOJ/woj-server/internal/misc/log"
|
||||
@ -28,7 +29,7 @@ func RunRunner(i *do.Injector) error {
|
||||
|
||||
srv := asynq.NewServer(
|
||||
asynq.RedisClientOpt{
|
||||
Addr: conf.Redis.Address,
|
||||
Addr: fmt.Sprintf("%s:%d", conf.Redis.Address, conf.Redis.Port),
|
||||
Password: conf.Redis.Password,
|
||||
DB: conf.Redis.QueueDb,
|
||||
},
|
||||
|
@ -53,7 +53,7 @@ func RunServer(i *do.Injector) error {
|
||||
}
|
||||
queueSrv := asynq.NewServer(
|
||||
asynq.RedisClientOpt{
|
||||
Addr: conf.Redis.Address,
|
||||
Addr: fmt.Sprintf("%s:%d", conf.Redis.Address, conf.Redis.Port),
|
||||
Password: conf.Redis.Password,
|
||||
DB: conf.Redis.QueueDb,
|
||||
},
|
||||
|
@ -11,6 +11,7 @@ type ConfigRedis struct {
|
||||
Db int `yaml:"Db"`
|
||||
QueueDb int `yaml:"QueueDb"`
|
||||
Address string `yaml:"Address"`
|
||||
Port int `yaml:"Port"`
|
||||
Password string `yaml:"Password"`
|
||||
}
|
||||
|
||||
|
3
internal/repo/cache/redis.go
vendored
3
internal/repo/cache/redis.go
vendored
@ -2,6 +2,7 @@ package cache
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"git.0x7f.app/WOJ/woj-server/internal/misc/config"
|
||||
"git.0x7f.app/WOJ/woj-server/internal/misc/log"
|
||||
"github.com/redis/go-redis/v9"
|
||||
@ -22,7 +23,7 @@ func NewService(i *do.Injector) (Service, error) {
|
||||
srv.log = do.MustInvoke[log.Service](i).GetLogger("redis")
|
||||
|
||||
conf := do.MustInvoke[config.Service](i).GetConfig()
|
||||
srv.setup(conf.Redis.Address, conf.Redis.Password, conf.Redis.Db)
|
||||
srv.setup(fmt.Sprintf("%s:%d", conf.Redis.Address, conf.Redis.Port), conf.Redis.Password, conf.Redis.Db)
|
||||
return srv, srv.err
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package task
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.0x7f.app/WOJ/woj-server/internal/e"
|
||||
"git.0x7f.app/WOJ/woj-server/internal/misc/config"
|
||||
"git.0x7f.app/WOJ/woj-server/internal/misc/log"
|
||||
@ -29,7 +30,7 @@ func NewService(i *do.Injector) (Service, error) {
|
||||
conf := do.MustInvoke[config.Service](i).GetConfig()
|
||||
|
||||
redisOpt := asynq.RedisClientOpt{
|
||||
Addr: conf.Redis.Address,
|
||||
Addr: fmt.Sprintf("%s:%d", conf.Redis.Address, conf.Redis.Port),
|
||||
Password: conf.Redis.Password,
|
||||
DB: conf.Redis.QueueDb,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user