Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
LockModel with a TTL Index
public class LockModel
{
public string Id { get; set; }
/// <summary>
/// I'm going to set this to the moment in time when the lock should be cleared.
/// </summary>
public DateTime ExpireAt { get; set; }
}
// In our LockProvider constructor...
// Specify a TTL index on the ExpiryPoint field.
collection.Indexes.CreateOne(new CreateIndexModel<LockModel>(
Builders<LockModel>.IndexKeys.Ascending(l => l.ExpireAt),
new CreateIndexOptions
{
ExpireAfter = TimeSpan.Zero
}
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.