• This repository has been archived on 02/Jan/2024
  • Stars
    star
    480
  • Rank 91,562 (Top 2 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 16 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Generates universally unique identifiers (UUIDs) for use in distributed applications.

UUID Generator¶ ↑

Generates universally unique identifiers (UUIDs) for use in distributed applications. Based on RFC 4122.

Generating UUIDs¶ ↑

Call #generate to generate a new UUID. The method returns a string in one of three formats. The default format is 36 characters long, and contains the 32 hexadecimal octets and hyphens separating the various value parts. The :compact format omits the hyphens, while the :urn format adds the :urn:uuid prefix.

For example:

uuid = UUID.new
10.times do
  p uuid.generate
end

UUIDs in Brief¶ ↑

UUID (universally unique identifier) are guaranteed to be unique across time and space.

A UUID is 128 bit long, and consists of a 60-bit time value, a 16-bit sequence number and a 48-bit node identifier.

The time value is taken from the system clock, and is monotonically incrementing. However, since it is possible to set the system clock backward, a sequence number is added. The sequence number is incremented each time the UUID generator is started. The combination guarantees that identifiers created on the same machine are unique with a high degree of probability.

Note that due to the structure of the UUID and the use of sequence number, there is no guarantee that UUID values themselves are monotonically incrementing. The UUID value cannot itself be used to sort based on order of creation.

To guarantee that UUIDs are unique across all machines in the network, the IEEE 802 MAC address of the machine’s network interface card is used as the node identifier.

For more information see RFC 4122.

UUID State File¶ ↑

The UUID generator uses a state file to hold the MAC address and sequence number.

The MAC address is used to generate identifiers that are unique to your machine, preventing conflicts in distributed applications. The MAC address is six bytes (48 bit) long. It is automatically extracted from one of the network cards on your machine.

The sequence number is incremented each time the UUID generator is first used by the application, to prevent multiple processes from generating the same set of identifiers, and deal with changes to the system clock.

The UUID state file is created in #Dir.tmpdir/ruby-uuid or the Windows common application data directory using mode 0644. If that directory is not writable, the file is created as .ruby-uuid in the home directory. If you need to create the file with a different mode, use UUID#state_file before running the UUID generator.

Note: If you are running on a shared host where the state file is not shared between processes, or persisted across restarts (e.g. Heroku, Google App Engine) you can simple turn it off:

UUID.state_file = false

State files are not portable across machines.

If you do not use the state file, UUID generation will attempt to use your server’s MAC address using the macaddr gem, which runs system commands to identify the MAC address and then cache it. Since this can take a few seconds on some operating systems, when using UUID.state_file = false, you should add the following line after disabling the state file:

UUID.generator.next_sequence

Note: when using a forking server (Unicorn, Resque, Pipemaster, etc) you don’t want your forked processes using the same sequence number. Make sure to increment the sequence number each time a worker forks.

For example, in config/unicorn.rb:

after_fork do |server, worker|
  UUID.generator.next_sequence
end

Command Line¶ ↑

You can run uuid from the command line, generating new UUID to stdout:

$ uuid

Multiple UUIDs in a sequence, separated with a newline:

$ uuid --count 10

You can also run client and server from the command line

$ uuid --server &
$ uuid --socket /var/lib/uuid.sock

Latest and Greatest¶ ↑

Source code and documentation hosted on Github: github.com/assaf/uuid

To get UUID from source:

git clone git://github.com/assaf/uuid.git

License¶ ↑

This package is licensed under the MIT license and/or the Creative Commons Attribution-ShareAlike.

:include: MIT-LICENSE

More Repositories

1

zombie

Insanely fast, full-stack, headless browser testing using node.js
JavaScript
5,656
star
2

vanity

Experiment Driven Development for Ruby
Ruby
1,546
star
3

node-replay

When API testing slows you down: record and replay HTTP responses like a boss
JavaScript
522
star
4

node-passbook

iOS Passbook for the Node hacker
JavaScript
280
star
5

rack-oauth2-server

LOOKING FOR MAINTAINER — OAuth 2.0 Authorization Server as a Rack module
Ruby
232
star
6

scrapi

LOOKING FOR A MAINTAINER
Ruby
157
star
7

fine-tune

👋 The missing UI for working with OpenAI: manage your files, and fine tune models.
TypeScript
76
star
8

ironium

Job queues and scheduled jobs for Node.js, Beanstalkd and/or Iron.io.
JavaScript
72
star
9

sideline

Sideline, a CoffeeScript shell for your server (NO LONGER MAINTAINED)
CoffeeScript
39
star
10

whisper-to-me

SVG graphs from Whisper files
CoffeeScript
37
star
11

necktie

NO LONGER MAINTAINED
Ruby
30
star
12

ruby-in-practice

Source code and examples from the book Ruby In Practice
Ruby
29
star
13

queue-run

👋 Web 2.0 framework to make building back-ends and APIs easy and fun: HTTP, FIFO queues, WebSocket, and more …
TypeScript
26
star
14

pipemaster

NO LONGER MAINTAINED
Ruby
24
star
15

css-annotate

The Annotated CSS tells you which style to use where
Ruby
23
star
16

octolog

Github is our single sign-on octopus
CoffeeScript
20
star
17

reliable-msg

NO LONGER MAINTAINED
Ruby
15
star
18

dailyhi

Start the morning with a friendly Hi in your inbox.
Ruby
12
star
19

archive-2005

Ruby
10
star
20

highfive

HTML 5/CSS 3/jQuery goodness
Ruby
9
star
21

vanity.js

NO LONGER MAINTAINED
CoffeeScript
8
star
22

lazybird

Lazy promises using Bluebird (NO LONGER MAINTAINED)
JavaScript
4
star
23

react-one-tap

Google One Tap sign-in for React
TypeScript
4
star
24

assaf

1
star