Skip to content

Commit

Permalink
update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Fengxq2014 committed Jan 20, 2024
1 parent 4cd0ad0 commit 71eb1f6
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
[![Build Status](https://travis-ci.org/Fengxq2014/mars.svg?branch=master)](https://travis-ci.org/Fengxq2014/mars)

一个分布式、高性能的雪花id生成器
* 标准雪花id
* 53位兼容前端js精度的短雪花id
* 自增序列(按时间【分钟、小时、天、月、年】回退、按最大值回退)
* 批量获取id

## 依赖
* etcd 一个高可用的分布式键值(key-value)数据库,etcd内部采用raft协议作为一致性算法
Expand All @@ -23,6 +27,23 @@
```base
$ curl -u name:passwd 'http://{host}/id'
$ 530749286099451904%
$ # 批量获取
$ curl -u name:passwd 'http://{host}/id?num=10'
```
* 获取53位id
```base
$ curl -u name:passwd 'http://{host}/id53'
$ 4122703036416%
$ # 批量获取
$ curl -u name:passwd 'http://{host}/id53?num=10'
```
* 获取序列号
```base
$ # {id}:为序列号id,需要按照业务规则进行预先配置
$ curl -u name:passwd 'http://{host}/seq/{id}'
$ 1%
$ # 批量获取
$ curl -u name:passwd 'http://{host}/seq/{id}?num=10'
```
* 解析id信息
```$xslt
Expand All @@ -33,7 +54,22 @@
* 使用redis-cli
```base
$ redis-cli auth
$ # 获取一个标准id
$ get id
$ #批量获取10个
$ lrange id 0 10
$ # 获取一个53位id
$ get id53
$ #批量获取10个
$ lrange id53 0 10
$ # 获取一个序列号 {id}:为序列号id,需要按照业务规则进行预先配置
$ get seq/{id}
$ #批量获取10个
$ lrange seq/{id} 0 10
```
* 使用其他redis client 请使用redis sentinel 模式

Expand All @@ -43,6 +79,17 @@
### tcp
使用redis auth

## seq.conf配置
```json
[
{
"id": "1",
"timeRollback": "m", // 按时间回退(m:分钟,h:小时,d:天,M:月,y:年)
"numRollback": 1000 // 按最大值回退
}
]
```

## 节点状态流程图
[![image.png](https://i.postimg.cc/jdtXdGKv/image.png)](https://postimg.cc/z32Wx2yR)

Expand Down

0 comments on commit 71eb1f6

Please sign in to comment.