flike / idgo Goto Github PK
View Code? Open in Web Editor NEWid generator based on MySQL
id generator based on MySQL
不用replace,用update,看看文档吧
:)
根据官方文档描述,每秒可生成大约20w个id。
通过java redis客户端jedis进行测试,每秒平均只能生成7754个id。测试代码如下:
// 通过java redis客户端测试idgo每秒生成id数
public class JRedisUtil {
private static JRedisUtil instance = new JRedisUtil();
private Jedis jedis = null;
{
String host = "127.0.0.1";
int port = 6389;
jedis = new Jedis(host, port);
}
public String get(String key) {
return jedis.get(key);
}
public void set(String key, String value) {
jedis.set(key, value);
}
private JRedisUtil() {
}
public static JRedisUtil getInstance() {
return instance;
}
public static void main(String[] args) {
JRedisUtil util = JRedisUtil.getInstance();
long i = 1;
long start = System.currentTimeMillis();
for(i=1;;i++) {
String value = util.get("abc");
System.out.println(value);
long end = System.currentTimeMillis();
long interval = end - start;
if(interval >= 1000) {
break;
}
}
System.out.println("Done!");
System.out.println("i = " + i);
// total: 7787 7960 8452 6974 6907 6748 8017 8164 8272 8266 // 共测试10次
// avg: 7754.7 // 平均每秒生成id数
}
}
----当ID生成器服务崩溃后,可以继续生成有效ID,避免了ID回绕的风险。
如果idgo突然崩溃了,之前批量生成的id会丢失吧,如何保证id连续呢?
In redis delete a key:
127.0.0.1:6379> del a
(integer) 1
In idgo delete a key:
127.0.0.1:6389> del abc
OK
I use python redis to connect idgo, when delete a key, I got a error:
Traceback (most recent call last):
File "./idgo_concurrent_test.py", line 82, in <module>
r.delete("id_test")
File "/usr/lib/python2.7/dist-packages/redis/client.py", line 841, in delete
return self.execute_command('DEL', *names)
File "/usr/lib/python2.7/dist-packages/redis/client.py", line 573, in execute_command
return self.parse_response(connection, command_name, **options)
File "/usr/lib/python2.7/dist-packages/redis/client.py", line 587, in parse_response
return self.response_callbacks[command_name](response, **options)
ValueError: invalid literal for int() with base 10: 'OK'
make
go install ./...
config/config.go:6:2: cannot find package "github.com/BurntSushi/toml" in any of:
/usr/local/go/src/github.com/BurntSushi/toml (from $GOROOT)
/usr/local/src/github.com/BurntSushi/toml (from $GOPATH)
cmd/idgo/main.go:13:2: cannot find package "github.com/flike/golog" in any of:
/usr/local/go/src/github.com/flike/golog (from $GOROOT)
/usr/local/src/github.com/flike/golog (from $GOPATH)
server/idgo.go:8:2: cannot find package "github.com/go-sql-driver/mysql" in any of:
/usr/local/go/src/github.com/go-sql-driver/mysql (from $GOROOT)
/usr/local/src/github.com/go-sql-driver/mysql (from $GOPATH)
make: *** [build] Error 1
see title .
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.