diff --git a/rooms/rooms_manager.go b/rooms/rooms_manager.go index 431a8ce..1158726 100644 --- a/rooms/rooms_manager.go +++ b/rooms/rooms_manager.go @@ -7,6 +7,7 @@ import ( "fmt" "log" "math/rand" + "time" "github.com/redis/go-redis/v9" ) @@ -57,6 +58,7 @@ type RoomManager interface { } const roomRedisPrefix = "room" +const roomTtl = 24 * time.Hour func roomNameToRedisId(roomName string) string { return fmt.Sprintf("%s:%s", roomRedisPrefix, roomName) @@ -155,7 +157,7 @@ func (redisRM RedisRM) Update(ctx context.Context, roomName string, f func(fromR _, err = tx.Pipelined(ctx, func(pipe redis.Pipeliner) error { log.Printf(">> about to Set %s to %v", roomName, room) - pipe.Set(ctx, roomKey, &room, 0) + pipe.Set(ctx, roomKey, &room, roomTtl) return nil }) @@ -178,6 +180,6 @@ func (redisRM RedisRM) Update(ctx context.Context, roomName string, f func(fromR } 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? + err := redisRM.Rdb.Set(ctx, roomNameToRedisId(room.Name), &room, roomTtl).Err() return err }