Skip to content

Commit

Permalink
docs: Explain why we usa a lua script to update a record
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricioabreu committed Apr 25, 2024
1 parent b67aa0e commit 1647d77
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/db/redistore/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ func NewOriginStore(client *redis.Client, cfg *config.Config) *OriginStore {
}
}

// Update updates the origin in the store with the given ttl.
// It uses a lua script to ensure that the origin is only updated if the address (value)
// is the same as the current one or if the origin (key) does not exist.
// It is crucial to use a lua script to avoid other origins to overwrite the current one,
// causing glitches in the video streaming.
func (s *OriginStore) Update(ctx context.Context, origin service.Origin) error {
var updateOrigin = redis.NewScript(`
local key = KEYS[1]
Expand Down

0 comments on commit 1647d77

Please sign in to comment.