Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/joymoe/ksuid.net

K-Sortable Globally Unique IDs for .Net
https://github.com/joymoe/ksuid.net

ksuid unique-id uuid

Last synced: 13 days ago
JSON representation

K-Sortable Globally Unique IDs for .Net

Awesome Lists containing this project

README

        

# Ksuid

This library implements the [K-Sortable Globally Unique IDs](https://github.com/segmentio/ksuid) from Segment. See also the article called [A Brief History of the UUID](https://segment.com/blog/a-brief-history-of-the-uuid/).

> KSUID is for K-Sortable Unique IDentifier. It's a way to generate globally unique IDs similar to RFC 4122 UUIDs, but contain a time component so they can be "roughly" sorted by time of creation. The remainder of the KSUID is randomly generated bytes.

[![AppVeyor](https://img.shields.io/appveyor/ci/JoyMoe/ksuid-net.svg)](https://ci.appveyor.com/project/JoyMoe/ksuid-net)
[![license](https://img.shields.io/github/license/JoyMoe/Ksuid.Net.svg)](https://github.com/JoyMoe/Ksuid.Net/blob/master/LICENSE)
[![NuGet](https://img.shields.io/nuget/v/Ksuid.svg)](https://www.nuget.org/packages/Ksuid)
[![NuGet](https://img.shields.io/nuget/vpre/Ksuid.svg)](https://www.nuget.org/packages/Ksuid/absoluteLatest)
![net462](https://img.shields.io/badge/.Net-4.6.2-brightgreen.svg)
![netstandard2.0](https://img.shields.io/badge/.Net-netstandard2.0-brightgreen.svg)

## Installation

To install Ksuid, run the following command in the Package Manager Console

```powershell
PM> Install-Package Ksuid
```

## Usage

```csharp
using KSUID;

var ksuid1 = Ksuid.Generate(); // same as new Ksuid()
Console.WriteLine(ksuid1);
Console.WriteLine(ksuid1.GetTimestamp());
Console.WriteLine(ksuid1.GetUnixTimestamp());

var ksuid2 = Ksuid.FromString("0o5Fs0EELR0fUjHjbCnEtdUwQe3");
Console.WriteLine(ksuid2);
Console.WriteLine(ksuid2.GetTimestamp());
Console.WriteLine(ksuid2.GetUnixTimestamp());

var ksuid3 = new Ksuid(ksuid2.GetPayload());
Console.WriteLine(ksuid3);
Console.WriteLine(ksuid3.GetTimestamp());
Console.WriteLine(ksuid3.GetUnixTimestamp());

var ksuid4 = new Ksuid(ksuid2.GetPayload(), ksuid1.GetTimestamp());
Console.WriteLine(ksuid4);
Console.WriteLine(ksuid4.GetTimestamp());
Console.WriteLine(ksuid4.GetUnixTimestamp());

var ksuid4 = Ksuid.FromByteArray(ksuid2.ToByteArray());
Console.WriteLine(ksuid4);
```

## License

The MIT License

More info see [LICENSE](LICENSE)