1
0
mirror of synced 2025-12-16 18:18:10 +08:00

auto commit

This commit is contained in:
zhouzj
2021-03-25 00:41:06 +08:00
parent 60de761e14
commit 3a2013982f
5 changed files with 14 additions and 5 deletions

View File

@@ -66,7 +66,11 @@ namespace Yitter.IdGenerator
protected int _GenCountInOneTerm = 0; protected int _GenCountInOneTerm = 0;
protected int _TermIndex = 0; protected int _TermIndex = 0;
//private static long _StartTimeTick = 0;
//private static long _BaseTimeTick = 0;
public Action<OverCostActionArg> GenAction { get; set; } public Action<OverCostActionArg> GenAction { get; set; }
public SnowWorkerM1(IdGeneratorOptions options) public SnowWorkerM1(IdGeneratorOptions options)
{ {
@@ -104,6 +108,9 @@ namespace Yitter.IdGenerator
_TimestampShift = (byte)(WorkerIdBitLength + SeqBitLength); _TimestampShift = (byte)(WorkerIdBitLength + SeqBitLength);
_CurrentSeqNumber = options.MinSeqNumber; _CurrentSeqNumber = options.MinSeqNumber;
//_BaseTimeTick = BaseTime.Ticks;
//_StartTimeTick = (long)(DateTime.UtcNow.Subtract(BaseTime).TotalMilliseconds) - Environment.TickCount;
} }
@@ -314,6 +321,8 @@ namespace Yitter.IdGenerator
protected virtual long GetCurrentTimeTick() protected virtual long GetCurrentTimeTick()
{ {
//return (long)(DateTime.UtcNow - BaseTime).Ticks;
//return (long)(_StartTimeTick + Environment.TickCount);
return (long)(DateTime.UtcNow - BaseTime).TotalMilliseconds; return (long)(DateTime.UtcNow - BaseTime).TotalMilliseconds;
} }
@@ -332,7 +341,7 @@ namespace Yitter.IdGenerator
public virtual long NextId() public virtual long NextId()
{ {
lock (_SyncLock) lock (_SyncLock)
{ {
return _IsOverCost ? NextOverCostId() : NextNormalId(); return _IsOverCost ? NextOverCostId() : NextNormalId();
} }

View File

@@ -8,7 +8,7 @@ package contract
type IdGeneratorOptions struct { type IdGeneratorOptions struct {
Method uint16 // 雪花计算方法,1-漂移算法|2-传统算法默认1 Method uint16 // 雪花计算方法,1-漂移算法|2-传统算法默认1
BaseTime int64 // 基础时间,不能超过当前系统时间 BaseTime int64 // 基础时间ms单位,不能超过当前系统时间
WorkerId uint16 // 机器码,与 WorkerIdBitLength 有关系 WorkerId uint16 // 机器码,与 WorkerIdBitLength 有关系
WorkerIdBitLength byte // 机器码位长范围1-21要求序列数位长+机器码位长不超过22 WorkerIdBitLength byte // 机器码位长范围1-21要求序列数位长+机器码位长不超过22
SeqBitLength byte // 序列数位长范围2-21要求序列数位长+机器码位长不超过22 SeqBitLength byte // 序列数位长范围2-21要求序列数位长+机器码位长不超过22

View File

@@ -17,7 +17,7 @@ public class IdGeneratorOptions {
public short Method = 1; public short Method = 1;
/** /**
* 基础时间 * 基础时间ms单位
* 不能超过当前系统时间 * 不能超过当前系统时间
*/ */
public long BaseTime = 1582136402000L; public long BaseTime = 1582136402000L;

View File

@@ -187,7 +187,7 @@ Rust[查看示例][4]
QQ群646049993 QQ群646049993
即将推出 C/Rust 等版本。 即将推出 C 等版本。
[1]: https://gitee.com/yitter/idgenerator/tree/master/C%23.NET [1]: https://gitee.com/yitter/idgenerator/tree/master/C%23.NET

View File

@@ -6,7 +6,7 @@
pub struct IdGeneratorOptions { pub struct IdGeneratorOptions {
/// 雪花计算方法,1-漂移算法|2-传统算法默认1 /// 雪花计算方法,1-漂移算法|2-传统算法默认1
pub Method: u8, pub Method: u8,
/// 基础时间,不能超过当前系统时间 /// 基础时间ms单位,不能超过当前系统时间
pub BaseTime: i64, pub BaseTime: i64,
/// 机器码,与 WorkerIdBitLength 有关系 /// 机器码,与 WorkerIdBitLength 有关系
pub WorkerId: u32, pub WorkerId: u32,