dogtag 1.0.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +51 -0
- data/lib/dogtag.rb +1 -0
- data/lib/dogtag/lua_script.rb +13 -0
- data/lib/dogtag/request.rb +5 -8
- data/lib/dogtag/version.rb +1 -1
- data/lua/{id-generation.lua → id-generation.lua.erb} +4 -4
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8cab26a320943028ef31bc9c2d2f9822a7b39e9
|
4
|
+
data.tar.gz: 0dcf654f1701ee9fdab5226334a3b891c2763d02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb0b80cd108a4d764b2c3687a023d3b98c6c5e94b41589bf225f8248e6faa35d7ec6db4874235f05ceeb3ccaae93d7d9dadb502f4747d36790c2173c74a5147c
|
7
|
+
data.tar.gz: e42789e6244c87af765a0d235e874c089a3d33e0c90f230fb7796645a6a8e15b18998f6e7ec87dbb33e314f49bbc61ea3e71da33c9beaff4372b9d27f37a9d75
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
Dogtag
|
2
|
+
======
|
3
|
+
|
4
|
+
A Redis-powered Ruby client for generating unique IDs with Redis for use in distributed systems. Based heavily off of [Icicle](https://github.com/intenthq/icicle/) and [Twitter Snowflake](https://github.com/intenthq/icicle/)
|
5
|
+
|
6
|
+
Requirements
|
7
|
+
------------
|
8
|
+
- [Ruby](https://www.ruby-lang.org)
|
9
|
+
- [Redis](https://redis.io/)
|
10
|
+
|
11
|
+
Installation
|
12
|
+
------------
|
13
|
+
|
14
|
+
Simply add `gem 'dogtag'` to your `Gemfile` and run `bundle`
|
15
|
+
|
16
|
+
Configuration
|
17
|
+
-------------
|
18
|
+
|
19
|
+
To configure the connection to your Redis server simply set the `REDIS_URL` environment variable. By default it will connect to `redis://localhost:6379`.
|
20
|
+
|
21
|
+
To set the range of logical shard IDs this server should manage, run the command below replacing the number range with a range of numbers, of which none can be shared with another Redis server. If a logical shard ID is shared a separate Redis instance, you may get ID collisions.
|
22
|
+
|
23
|
+
```shell
|
24
|
+
bundle exec ruby -e 'require "dogtag"; Dogtag.logical_shard_id_range = 0..31'
|
25
|
+
```
|
26
|
+
|
27
|
+
*Note: The available shard ID numbers are current 0 - 31.*
|
28
|
+
|
29
|
+
Usage
|
30
|
+
-------
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
data_type = 0
|
34
|
+
Dogtag.generate_id data_type
|
35
|
+
```
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
data_type = 42
|
39
|
+
count = 100
|
40
|
+
Dogtag.generate_id data_type, count
|
41
|
+
```
|
42
|
+
|
43
|
+
*Note: The available data type ID numbers are current 0 - 255.*
|
44
|
+
|
45
|
+
Related Projects
|
46
|
+
----------------
|
47
|
+
- __[dogtag-web](https://github.com/zillyinc/dogtag-web)__ - Web API for dogtag
|
48
|
+
|
49
|
+
TODO
|
50
|
+
----
|
51
|
+
- Support multiple Redis servers
|
data/lib/dogtag.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
module Dogtag
|
2
|
+
module LuaScript
|
3
|
+
LUA_SCRIPT_PATH = 'lua/id-generation.lua.erb'.freeze
|
4
|
+
|
5
|
+
def self.to_s
|
6
|
+
@rendered_script ||= ERB.new(
|
7
|
+
File.read(
|
8
|
+
File.expand_path "../../#{LUA_SCRIPT_PATH}", File.dirname(__FILE__)
|
9
|
+
)
|
10
|
+
).result
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/dogtag/request.rb
CHANGED
@@ -2,7 +2,6 @@ module Dogtag
|
|
2
2
|
class Request
|
3
3
|
include Dogtag::Mixins::Redis
|
4
4
|
|
5
|
-
LUA_SCRIPT_PATH = 'lua/id-generation.lua'.freeze
|
6
5
|
MAX_TRIES = 5
|
7
6
|
|
8
7
|
def initialize(data_type, count = 1)
|
@@ -26,14 +25,12 @@ module Dogtag
|
|
26
25
|
|
27
26
|
attr_reader :data_type, :count
|
28
27
|
|
29
|
-
def
|
30
|
-
|
31
|
-
File.expand_path "../../#{LUA_SCRIPT_PATH}", File.dirname(__FILE__)
|
32
|
-
)
|
28
|
+
def lua_script_sha
|
29
|
+
@@lua_script_sha ||= redis.script(:load, LuaScript.to_s)
|
33
30
|
end
|
34
31
|
|
35
|
-
def
|
36
|
-
|
32
|
+
def lua_keys
|
33
|
+
@lua_keys ||= [ data_type, count ]
|
37
34
|
end
|
38
35
|
|
39
36
|
# NOTE: If too many requests come in inside of a millisecond the Lua script
|
@@ -54,7 +51,7 @@ module Dogtag
|
|
54
51
|
end
|
55
52
|
|
56
53
|
def redis_response
|
57
|
-
@redis_response ||= redis.
|
54
|
+
@redis_response ||= redis.evalsha(lua_script_sha, keys: lua_keys)
|
58
55
|
end
|
59
56
|
end
|
60
57
|
end
|
data/lib/dogtag/version.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
local logical_shard_id_range_key = '
|
1
|
+
local logical_shard_id_range_key = '<%= Dogtag::LOGICAL_SHARD_ID_RANGE_KEY %>'
|
2
2
|
local last_logical_shard_id_key = 'dogtag-generator-last-logical-shard-id'
|
3
|
+
local max_sequence = <%= Dogtag::MAX_SEQUENCE %>
|
3
4
|
|
4
|
-
local
|
5
|
-
local
|
6
|
-
local num_ids = tonumber(KEYS[3])
|
5
|
+
local data_type = tonumber(KEYS[1])
|
6
|
+
local num_ids = tonumber(KEYS[2])
|
7
7
|
|
8
8
|
-- Allow one server to acts as multiple shards
|
9
9
|
local logical_shard_id_range = redis.call('SORT', logical_shard_id_range_key)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dogtag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Crownoble
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -45,15 +45,17 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
+
- README.md
|
48
49
|
- lib/dogtag.rb
|
49
50
|
- lib/dogtag/generator.rb
|
50
51
|
- lib/dogtag/id.rb
|
52
|
+
- lib/dogtag/lua_script.rb
|
51
53
|
- lib/dogtag/mixins/redis.rb
|
52
54
|
- lib/dogtag/request.rb
|
53
55
|
- lib/dogtag/response.rb
|
54
56
|
- lib/dogtag/timestamp.rb
|
55
57
|
- lib/dogtag/version.rb
|
56
|
-
- lua/id-generation.lua
|
58
|
+
- lua/id-generation.lua.erb
|
57
59
|
homepage: https://github.com/zillyinc/dogtag
|
58
60
|
licenses: []
|
59
61
|
metadata: {}
|