StackExchange / StackExchange/StackExchange.Redis

Stream Add with auto-generated ID is 5 seconds old

Open
#1,849 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
6.2k
Forks
1.6k
Avg merge
1d 15h
Merged PRs (30d)
43

Description

For some reason StreamAdd() and StreamAddAsync() when using auto-generated IDs are generating IDs from a Unix time milliseconds value that are roughly ~5s old.

Redis is running in docker:

docker run -d --restart always -p 6379:6379 redis

Sample application:

using System;
using System.Globalization;
using StackExchange.Redis;

using var redis = await ConnectionMultiplexer.ConnectAsync("localhost:6379");
var db = redis.GetDatabase();
             
Console.WriteLine($"Writing record at {DateTimeOffset.UtcNow}");
var result = await db.StreamAddAsync("test", "test", DateTime.UtcNow.ToString(CultureInfo.InvariantCulture));
var millis = long.Parse(result.ToString().Split('-')[0]);
Console.WriteLine($"Wrote record '{result}' ({DateTimeOffset.FromUnixTimeMilliseconds(millis)}) at {DateTimeOffset.UtcNow}");

Sample output:

Writing record at 27/08/2021 12:36:25 AM +00:00
Wrote record '1630024580206-0' (27/08/2021 12:36:20 AM +00:00) to redis stream 'test' at 27/08/2021 12:36:25 AM +00:00

I did not have the same issue when calling XADD via the Redis CLI.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the StreamAdd and StreamAddAsync paths that generate IDs when no explicit ID is supplied, using the C# sample application to reproduce the timestamp discrepancy. Compare the generated ID with the current Unix time and with Redis CLI XADD behavior; done means auto-generated IDs no longer appear roughly five seconds old.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, redis
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.