标签:结束 sleep 释放 ini init RoCE class 去重 art
import threading
import time
from redis import Redis
class Myredis(Redis):
def __init__(self):
super(Myredis, self).__init__(host="192.168.31.21", port=6379, db=0, password="a123456")
def mysetex(self,name,time,value):
print("this")
set_sign = self.setex(name,time,value)
if set_sign:
t1 = threading.Thread(target=self.whileSetTime,args=(name, time))
t1.start()
print("start")
print("my_process")
return 1
else:
print("锁被占用直接结束")
return 0
def whileSetTime(self,name,set_time):
set_time_p = set_time/2
self.over_sign = 1
print(set_time_p)
while(1):
time.sleep(set_time_p)
print("set time")
self.expire(name,set_time)
if not self.over_sign:
self.delete(name)
return 0
A = Myredis()
a= "test4"
A.mysetex(a,4,"2")
time.sleep(6)
print(A.get(a),A.ttl(a))
print("my work")
A.over_sign = 0
print("work is end")
标签:结束 sleep 释放 ini init RoCE class 去重 art
原文地址:https://www.cnblogs.com/wanderingfish/p/11037439.html