Storing UUID as base64 String

后端 未结 8 1375
青春惊慌失措
青春惊慌失措 2020-11-29 16:14

I have been experimenting with using UUIDs as database keys. I want to take up the least amount of bytes as possible, while still keeping the UUID representation human read

8条回答
  •  萌比男神i
    2020-11-29 16:35

    This is not exactly what you asked for (it isn't Base64), but worth looking at, because of added flexibility: there is a Clojure library that implements a compact 26-char URL-safe representation of UUIDs (https://github.com/tonsky/compact-uuids).

    Some highlights:

    • Produces strings that are 30% smaller (26 chars vs traditional 36 chars)
    • Supports full UUID range (128 bits)
    • Encoding-safe (uses only readable characters from ASCII)
    • URL/file-name safe
    • Lowercase/uppercase safe
    • Avoids ambiguous characters (i/I/l/L/1/O/o/0)
    • Alphabetical sort on encoded 26-char strings matches default UUID sort order

    These are rather nice properties. I've been using this encoding in my applications both for database keys and for user-visible identifiers, and it works very well.

提交回复
热议问题