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

  • 相关阅读:
    i'm all geared up
    android设置主题和自定义主题的方法
    &和&&的区别
    兼容IE与Firefox的js 复制代码
    实用的注册表单验证代码
    常用JavaScript属性和方法
    400多个JavaScript特效大全
    float引起层飘出父层的解决方法
    JavaScript常见兼容性处理
    多种方法实现checkbox全选、取消全选、删除功能
  • 原文地址:https://www.cnblogs.com/sidianok/p/14868262.html
Copyright © 2011-2022 走看看