zoukankan      html  css  js  c++  java
  • 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中的字节码,就是在内存中的一串整形数字而已。

  • 相关阅读:
    mac os 添加用户到组 命令
    mac下 codeigniter在apache下去掉index.php
    chrome的timeline中stalled问题解析
    Message Queue vs. Web Services?
    使用bootstrap框架的模态框与ckeditor产生冲突,ckeditor的弹出窗不可用时的解决方法
    file_get_contents微信头像等待时间过长的原因
    javascript学习笔记
    javascript学习笔记
    javascript学习笔记
    javascript学习笔记
  • 原文地址:https://www.cnblogs.com/sidianok/p/14868262.html
Copyright © 2011-2022 走看看