Loading...

Python TimeUUID

Temperature: 0 °C

蘇恆永 蘇恆永
author_tools

參考這一篇:
什麼時候讓用 time UUID,Url link 

StackOverflow 有人提供了一段 code:
Url link


public static String reorderTimeUUId(String originalTimeUUID)
    {
        StringTokenizer tokens = new StringTokenizer(originalTimeUUID, "-");
        if (tokens.countTokens() == 5)
        {
            String time_low = tokens.nextToken();
            String time_mid = tokens.nextToken();
            String time_high_and_version = tokens.nextToken();
            String variant_and_sequence = tokens.nextToken();
            String node = tokens.nextToken();

            return time_high_and_version + '-' + time_mid + '-' + time_low + '-' + variant_and_sequence + '-' + node;

        }

        return originalTimeUUID;
    }


把它翻成 python :

def getTimeUUID(uuidVar)
    # ref: http://stackoverflow.com/questions/8713873/is-python-uuid1-sequential-as-timestamps
    import uuid
    if not isinstance(uuidVar, uuid.UUID):
        uuidVar = uuid.uuid1()
    tmp = str(uuidVar)

    tokens = tmp.split("-")
    if len(tokens) == 5:
        time_low, time_mid, time_high_and_version, variant_and_sequence, node = tokens
        return time_high_and_version + '-' + time_mid + '-' + time_low + '-' + variant_and_sequence + '-' + node
    return tmp




原理是原本的 UUID (uuid1) 組合是:
time_low – time_mid – time_high_and_version – variant_and_sequence – node

轉成
time_high_and_version – time_mid – time_low – variant_and_sequence – node

這樣產生出來的 UUID 就可以按時間排序了.

三重湯城園區 Go

https://innstory.com/story-Python_TimeUUID-557
技術

Prev
 Python_Pragmatic_Unicode

Next
免費電子書下載 

Nearby Attractions

三重湯城園區-Nearby Attractions

  • 枋橋建學碑 Go
  • 淡水公司田溪橋遺蹟 Go
  • 滬尾?臺 Go
  • 周氏節孝坊 Go
  • 學海書院(今高氏宗祠) Go
  • 淡水海關碼頭 Go

About the Author

蘇恆永

重新pickup本能中

Visitor message

Leave some footprints to prove that you visited me

Recommended reading

Author's other related stories

Linux 連線數調校.

Linux 連線數調校.

最近常常遇到連線數太多(因為底層 WebService 太忙了). web 最後連不上的問題. 後來...

實用的 netstat 查詢連線指令

實用的 netstat 查詢...

以下是一些實用的 netstat 語法,可以檢查主機的連線數量: netstat na 顯示主機上所...

ankhsvn 使用非標準 ssh port, 及設定免密碼登入

ankhsvn 使用非標準 ...

ankhsvn https://ankhsvn.open.c...

Recommended reading

Other stories happened at this address

ankhsvn 使用非標準 ssh port, 及設定免密碼登入

ankhsvn 使用非標準 ...

ankhsvn https://ankhsvn.open.c...

Python Pragmatic Unicode

Python Pragmat...

記錄一下 Python Pragmatic Unicode ...

CentOS 5 更新 openssh 7.1p2 及 openssl 1.0.1s

CentOS 5 更新 op...

最近被 highlight openssh 必須更新至 .p. CentOS 真是有夠古老的, 一堆...

免費電子書下載

免費電子書下載

太晚看到了, 每天都有免費程式設計相關的電子書可以下載 ht...

Please select an option

error

Hi, thank you for your participation, but you cannot vote repeatedly~

Join innstory now and start recording your story.

"Innstory" is a place to store stories. We are committed to becoming a warm platform. Deepening the bonds between people is our direction.
We are convinced that the blockchain between people is not just a cold calculation. Join us now.

Wrong format