Module uuid
A “UUID” is a Universally unique identifier. If an application requires that a value be unique only within a single computer or on a single database, then a simple counter is better than a UUID, because getting a UUID is time-consuming (it requires a syscall). For clusters of computers, or widely distributed applications, UUIDs are better.
Below is list of all uuid
functions and members.
Name | Use |
---|---|
uuid.nil | A nil object |
uuid() uuid.bin() uuid.str() |
Get a UUID |
uuid.new() | Create a UUID |
uuid.fromstr() uuid.frombin() uuid_object:bin() uuid_object:str() |
Get a converted UUID |
uuid_object:isnil() | Check if a UUID is an all-zero value |
-
uuid.
new
() Create a UUID sequence. You can use it in an index over a uuid field. For example, to create such index for a space named test, say:
tarantool> box.space.test:create_index("pk", {parts={field = 1, type = 'uuid'}})
Now you can insert uuids into the space:
tarantool> box.space.test:insert{uuid.new()} --- - [e631fdcc-0e8a-4d2f-83fd-b0ce6762b13f] ... tarantool> box.space.test:insert{uuid.fromstr('64d22e4d-ac92-4a23-899a-e59f34af5479')} --- - [64d22e4d-ac92-4a23-899a-e59f34af5479] ... tarantool> box.space.test:select{} --- - - [64d22e4d-ac92-4a23-899a-e59f34af5479] - [e631fdcc-0e8a-4d2f-83fd-b0ce6762b13f] ...
Return: a UUID Rtype: cdata
-
uuid.
fromstr
(uuid_str) Parameters: - uuid_str – UUID in 36-byte hexadecimal string
Return: converted UUID
Rtype: cdata
-
uuid.
frombin
(uuid_bin) Parameters: - uuid_str – UUID in 16-byte binary string
Return: converted UUID
Rtype: cdata
-
object
uuid_object
-
uuid_object:
bin
([byte-order]) byte-order
can be one of next flags:- ‘l’ - little-endian,
- ‘b’ - big-endian,
- ‘h’ - endianness depends on host (default),
- ‘n’ - endianness depends on network
Parameters: - byte-order (string) – one of
'l'
,'b'
,'h'
or'n'
.
Return: UUID converted from cdata input value.
Rtype: 16-byte binary string
-
tarantool> uuid = require('uuid')
---
...
tarantool> uuid(), uuid.bin(), uuid.str()
---
- 16ffedc8-cbae-4f93-a05e-349f3ab70baa
- !!binary FvG+Vy1MfUC6kIyeM81DYw==
- 67c999d2-5dce-4e58-be16-ac1bcb93160f
...
tarantool> uu = uuid()
---
...
tarantool> #uu:bin(), #uu:str(), type(uu), uu:isnil()
---
- 16
- 36
- cdata
- false
...