redis的lpop與blpop的坑,以及字節碼的切片


項目部署上線,問題不斷,這次碰到兩個小問題,在一個地方發現,記錄一下。

第一個是Python對redis的操作

眾所周知,redis對於列表的操作有lpop與blpop的操作,

   # LIST COMMANDS
    def blpop(self, keys, timeout=0):
        """
        LPOP a value off of the first non-empty list
        named in the ``keys`` list.

        If none of the lists in ``keys`` has a value to LPOP, then block
        for ``timeout`` seconds, or until a value gets pushed on to one
        of the lists.

        If timeout is 0, then block indefinitely.
        """
        if timeout is None:
            timeout = 0
        keys = list_or_args(keys, None)
        keys.append(timeout)
        return self.execute_command('BLPOP', *keys)

上面的blpip的方法定義

下面是lpop的方法定義

    def lpop(self, name):
        "Remove and return the first item of the list ``name``"
        return self.execute_command('LPOP', name)

  直接從兩個方法的返回來看,沒有注釋說明返回類型[話說,這個真的太不方便了]。經過本人測試blop會返回一個元祖類型,參數分別為redis的key與具體內容[二進制]。

但lpop卻直接返回列表內容的二進制對象。

后面的字節碼切片就是因為這個發現了這個現象。

對於一個字節碼的切片盡然返回的是一個int類型的數字,就是具體索引為止的字節碼的10進制表示值。

剛學了一點C語言,一個字符理論跟int在內存中保存的形式都是一個字節的數字[8位]

所以Python中的字節碼,就是在內存中的一串整形數字而已。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM