• redis基本命令的演示:


    import redis 
    
    
    r = redis.Redis(host='127.0.0.1', port=6379,db = 0)
    #查看匹配redis的数据
    r.keys()
    #查看redis的大小
    r.dbsize()
    #设置redis的key/value值
    r.set('foo','zoo')
    #获取redis的对应键值的value
    r.get('foo')
    #删除redis的所有数据
    r.flushdb()
    
    
    #查看是否存在某个键值
    r.exists('key')
    >>> import redis
    >>> r = redis.Redis(host='127.0.0.1', port=6379)
    >>> r.set('foo','zoo')
    True
    >>> g.get('foo')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'g' is not defined
    >>> r.get('foo')
    'zoo'
    >>> r.dbsize()
    7L
    >>> r.delete('too')
    1
    >>> r.keys()
    ['luo', 'hello', 'wu', 'lang', 'num', 'fff']
    >>> r.save()
    True
    >>> r.get('wu')
    'yanlong'
    >>> a = r.get('wu')
    >>> dir(a)
    ['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
    >>> r.exists('wu')
    True
    >>> r.exists('w')
    False
    >>> a
    'yanlong'
    >>> r.__init__()
    >>> r.init()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: 'Redis' object has no attribute 'init'
    >>> 

    不错的一篇文章:https://github.com/andymccurdy/redis-py 

  • 相关阅读:
    我的2007, 兼谈些对技术的看法
    回帖整理: 关于"学习Java社区"更清晰的思路
    回帖整理: 创业心态
    我的世界观 by 爱因斯坦
    回帖整理: 论团队中的设计工作
    请大家帮我一个忙
    回帖整理: Java社区有什么可学的?
    SSL原理及应用(1)SSL协议体系结构
    文件和目录的访问控制(4) 审核规则
    强名称(2)引用强名称签名的程序集
  • 原文地址:https://www.cnblogs.com/blogofwyl/p/4612450.html
Copyright © 2020-2023  润新知