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中的字节码,就是在内存中的一串整形数字而已。

  • 相关阅读:
    在线程中进行读取并写入文件和wenjia
    Java里的IO流里的FileInputStream 的读取并在前打印行数!
    C++基础知识(前言)
    linux shell 笔记
    AngularJS图片上传功能的实现
    jQuery中事件绑定
    项目实践中--Git服务器的搭建与使用指南
    javascript跨浏览器事件对象类库
    完美运动框架(js)
    浅谈js中继承的理解和实现
  • 原文地址:https://www.cnblogs.com/sidianok/p/14868262.html
Copyright © 2011-2022 走看看