Python连接redis

2019-10-22  本文已影响0人  imjcw

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 方法试试。

上一篇下一篇

猜你喜欢

热点阅读