fix: request context to rooms manager
This commit is contained in:
@@ -50,8 +50,8 @@ func (r *Room) UnmarshalBinary(data []byte) error {
|
||||
// let's check whether it will be possible to save nested structs
|
||||
|
||||
type RoomManager interface {
|
||||
Get(roomName string) (Room, bool, error)
|
||||
Save(room Room) error
|
||||
Get(ctx context.Context, roomName string) (Room, bool, error)
|
||||
Save(ctx context.Context, room Room) error
|
||||
Update(ctx context.Context, roomName string, f func(fromRoom Room) (toRoom Room)) error
|
||||
Subscribe(ctx context.Context, roomName string) <-chan Room
|
||||
}
|
||||
@@ -66,9 +66,9 @@ type RedisRM struct {
|
||||
Rdb *redis.Client
|
||||
}
|
||||
|
||||
func (redisRM RedisRM) Get(roomName string) (Room, bool, error) {
|
||||
func (redisRM RedisRM) Get(ctx context.Context, roomName string) (Room, bool, error) {
|
||||
var readRoom Room
|
||||
err := redisRM.Rdb.Get(context.TODO(), roomNameToRedisId(roomName)).Scan(&readRoom)
|
||||
err := redisRM.Rdb.Get(ctx, roomNameToRedisId(roomName)).Scan(&readRoom)
|
||||
if err == redis.Nil {
|
||||
return Room{}, false, nil
|
||||
}
|
||||
@@ -177,7 +177,7 @@ func (redisRM RedisRM) Update(ctx context.Context, roomName string, f func(fromR
|
||||
return errors.New("update reached maximum amount of retries")
|
||||
}
|
||||
|
||||
func (redisRM RedisRM) Save(room Room) error {
|
||||
err := redisRM.Rdb.Set(context.TODO(), roomNameToRedisId(room.Name), &room, 0).Err() // maybe even set expiration?
|
||||
func (redisRM RedisRM) Save(ctx context.Context, room Room) error {
|
||||
err := redisRM.Rdb.Set(ctx, roomNameToRedisId(room.Name), &room, 0).Err() // maybe even set expiration?
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user