redis包安装

  1. pip install redis

编写程序

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

输出结果如下:

  1. imjcw@imjcwPC:~$ python redisTest.py
  2. True
  3. True
  4. gsdfgwfvwevfwgefwvef
  5. 86400

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