StackExchange / StackExchange/StackExchange.Redis
Stream Add with auto-generated ID is 5 seconds old
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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