項目部署上線,問題不斷,這次碰到兩個小問題,在一個地方發現,記錄一下。
第一個是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中的字節碼,就是在內存中的一串整形數字而已。