Skip to content

Commit

Permalink
Merge pull request #50 from codecrafters-io/fix-header-handling
Browse files Browse the repository at this point in the history
use actual kv pair count
  • Loading branch information
rohitpaulk authored Nov 21, 2023
2 parents d941063 + 64b36d4 commit 39562fb
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion internal/rdb_file_creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,15 @@ func (r *RDBFileCreator) Write(keyValuePairs []KeyValuePair) error {
}
}

if err := enc.WriteDBHeader(0, 5, 1); err != nil {
keysWithTtlCount := 0

for _, keyValuePair := range keyValuePairs {
if keyValuePair.expiryTs > 0 {
keysWithTtlCount++
}
}

if err := enc.WriteDBHeader(0, uint64(len(keyValuePairs)), uint64(keysWithTtlCount)); err != nil {
return err
}

Expand Down

0 comments on commit 39562fb

Please sign in to comment.