Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Create method changed to NewId #121

Merged
merged 1 commit into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Masa.Contrib.Data.IdGenerator.NormalGuid;

public class NormalGuidGenerator : IGuidGenerator
{
public Guid Create() => Guid.NewGuid();
public Guid NewId() => Guid.NewGuid();
}


Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ Masa.Contrib.Data.IdGenerator.SimpleGuid is a simple guid constructor that provi

````
IGuidGenerator generator;// Get it through DI, or get it through IdGeneratorFactory.GuidGenerator
generator.Create();//Create a unique id
generator.NewId();//Create a unique id
````
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ Masa.Contrib.Data.IdGenerator.NormalGuid是一个简单的Guid构造器,提供

```
IGuidGenerator generator;// 通过DI获取,或者通过IdGeneratorFactory.GuidGenerator获取
generator.Create();//创建唯一id
generator.NewId();//创建唯一id
```
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ Masa.Contrib.Data.IdGenerator.SequentialGuid is an ordered Guid constructor that

````
ISequentialGuidGenerator generator;// Obtained through DI, or obtained through IdGeneratorFactory.SequentialGuidGenerator
generator.Create();//Create a unique id
generator.NewId();//Create a unique id
````
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ Masa.Contrib.Data.IdGenerator.SequentialGuid是一个有序的Guid构造器,

```
ISequentialGuidGenerator generator;// 通过DI获取,或者通过IdGeneratorFactory.SequentialGuidGenerator获取
generator.Create();//创建唯一id
generator.NewId();//创建唯一id
```
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class SequentialGuidGenerator : ISequentialGuidGenerator

public SequentialGuidGenerator(SequentialGuidType guidType) => _guidType = guidType;

public Guid Create() => Create(_guidType);
public Guid NewId() => Create(_guidType);

public Guid Create(SequentialGuidType guidType)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The upgraded version supports distributed deployment, relies on Redis to provide

````
ISnowflakeGenerator generator;// Get it through DI, or get it through IdGeneratorFactory.SnowflakeGenerator
generator.Create();//Create a unique id
generator.NewId();//Create a unique id
````

### Parameters:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Masa.Contrib.Data.IdGenerator.Snowflake.Distributed.Redis是基于`Masa.Contrib.

```
ISnowflakeGenerator generator;// 通过DI获取,或者通过IdGeneratorFactory.SnowflakeGenerator获取
generator.Create();//创建唯一id
generator.NewId();//创建唯一id
```

### 参数:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public BaseIdGenerator(IWorkerProvider workerProvider, IdGeneratorOptions idGene
TimestampLeftShift = idGeneratorOptions.SequenceBits + idGeneratorOptions.WorkerIdBits;
}

public virtual long Create()
public virtual long NewId()
{
lock (Lock)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public MachineClockIdGenerator(IWorkerProvider workerProvider, IdGeneratorOption
LastTimestamp = GetCurrentTimestamp();
}

public override long Create()
public override long NewId()
{
lock (Lock)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Masa.Contrib.Data.IdGenerator.Snowflake is an id constructor based on snowflake

````
ISnowflakeGenerator generator;// Get it through DI, or get it through IdGeneratorFactory.SnowflakeGenerator
generator.Create();//Create a unique id
generator.NewId();//Create a unique id
````

### Parameters and FAQs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Masa.Contrib.Data.IdGenerator.Snowflake是一个基于雪花id的id构造器,

```
ISnowflakeGenerator generator;// 通过DI获取,或者通过IdGeneratorFactory.SnowflakeGenerator获取
generator.Create();//创建唯一id
generator.NewId();//创建唯一id
```

### 参数及常见问题:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public void Test()
List<Guid> guids = new();
for (int i = 0; i < count; i++)
{
guids.Add(new SequentialGuidGenerator(SequentialGuidType.SequentialAsString).Create());
guids.Add(new SequentialGuidGenerator(SequentialGuidType.SequentialAsString).NewId());
}
Assert.IsTrue(guids.Count == guids.Distinct().Count());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public void GlobalSetup()
services.AddSnowflake();
var serviceProvider = services.BuildServiceProvider();
_idGenerator = serviceProvider.GetRequiredService<IIdGenerator<System.Snowflake, long>>();
_idGenerator.Create();
_idGenerator.NewId();
}

[Benchmark]
public void SnowflakeByMillisecond()
{
_idGenerator.Create();
_idGenerator.NewId();
}
}

Expand All @@ -43,12 +43,12 @@ public void GlobalSetup()
services.AddSnowflake(options => options.TimestampType = TimestampType.Seconds);
var serviceProvider = services.BuildServiceProvider();
_idGenerator = serviceProvider.GetRequiredService<IIdGenerator<System.Snowflake, long>>();
_idGenerator.Create();
_idGenerator.NewId();
}

[Benchmark]
public void SnowflakeBySecond()
{
_idGenerator.Create();
_idGenerator.NewId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ public void GlobalSetup()
});
var serviceProvider = services.BuildServiceProvider();
_idGenerator = serviceProvider.GetRequiredService<IIdGenerator<System.Snowflake, long>>();
_idGenerator.Create();
_idGenerator.NewId();
}

[Benchmark]
public void Distributed()
{
_idGenerator.Create();
_idGenerator.NewId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public void GlobalSetup()
services.AddSnowflake(options => options.EnableMachineClock = true);
var serviceProvider = services.BuildServiceProvider();
_idGenerator = serviceProvider.GetRequiredService<IIdGenerator<System.Snowflake, long>>();
_idGenerator.Create();
_idGenerator.NewId();
}

[Benchmark]
public void MachineClockByMillisecond()
{
_idGenerator.Create();
_idGenerator.NewId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void TestEnableMachineClock()
List<long> ids = new();
while (count < 500000)
{
var id = idGenerator.Create();
var id = idGenerator.NewId();
ids.Add(id);
count++;
}
Expand All @@ -70,7 +70,7 @@ public void TestDisableMachineClock()
List<long> ids = new();
while (count < 500000)
{
var id = idGenerator.Create();
var id = idGenerator.NewId();
ids.Add(id);
count++;
}
Expand Down