python设置redis过期时间

import time
import redis

if __name__ == "__main__":
    try:
        conn=redis.StrictRedis(host='192.168.80.41')
        conn.set('name','蒋乐哥哥')
        conn.expire('name',10)
            #设置键的过期时间为10s
        for item in range(12):
            value=conn.get('name')
            if value != None:
                print(value.decode('utf8'))
            else:
                print('the key has been deleted...')
                break
            time.sleep(1)
    except Exception as err:
        print(err)

posted on 2018-11-06 12:52  枫飞飞  阅读(12401)  评论(0编辑  收藏  举报