Skip to content

Commit c1ed644

Browse files
committed
cleanup
1 parent 9518cac commit c1ed644

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

integration/stream_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestStream(t *testing.T) {
2525
"18446744073709551000-0",
2626
"name", "Earth",
2727
)
28-
c.DoLoosely("XADD",
28+
c.Do("XADD",
2929
"planets",
3030
"18446744073709551000-*",
3131
"name", "Pluto",

stream.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ func newStreamKey() *streamKey {
5757
}
5858

5959
// generateID doesn't lock the mutex
60-
func (s *streamKey) generateID(now time.Time) string {
61-
ts := uint64(now.UnixMilli())
62-
60+
func (s *streamKey) generateID(ts uint64) string {
6361
next := fmt.Sprintf("%d-%d", ts, 0)
6462
if s.lastAllocatedID != "" && streamCmp(s.lastAllocatedID, next) >= 0 {
6563
last, _ := parseStreamID(s.lastAllocatedID)
@@ -238,13 +236,13 @@ func (s *streamKey) add(entryID string, values []string, now time.Time) (string,
238236

239237
switch {
240238
case entryID == "" || entryID == "*":
241-
entryID = s.generateID(now)
239+
entryID = s.generateID(uint64(now.UnixMilli()))
242240
default:
243241
// "<timestamp>-*"
244242
parts := strings.Split(entryID, "-")
245243
if len(parts) == 2 && parts[1] == "*" {
246-
if ts, err := strconv.Atoi(parts[0]); err == nil {
247-
entryID = s.generateID(time.UnixMilli(int64(ts)))
244+
if ts, err := strconv.ParseUint(parts[0], 10, 64); err == nil {
245+
entryID = s.generateID(uint64(ts))
248246
}
249247
}
250248
}

0 commit comments

Comments
 (0)