美文网首页
Python连接redis

Python连接redis

作者: imjcw | 来源:发表于2019-10-22 13:04 被阅读0次

    redis包安装

    pip install redis
    

    编写程序

    # -*- coding: utf-8 -*-
    
    from redis import Redis
    
    handler = Redis(host='127.0.0.1')
    print(handler.set('wx:accesstoken', 'gsdfgwfvwevfwgefwvef'))
    print(handler.expire('wx:accesstoken', 86400))
    print(handler.get('wx:accesstoken'))
    print(handler.ttl('wx:accesstoken'))
    

    输出结果如下:

    imjcw@imjcwPC:~$ python redisTest.py
    True
    True
    gsdfgwfvwevfwgefwvef
    86400
    

    如果想要知道 redis 有哪些方法,可以通过 help 方法试试。

    相关文章

      网友评论

          本文标题:Python连接redis

          本文链接:https://www.haomeiwen.com/subject/fckjkctx.html