import redis


def delete_key():
    r = redis.StrictRedis.from_url('redis://:ReDis!GmTx*0aN6@172.16.40.133:6379')
    keys = r.keys("TS:recommend_diary_set:device_id:*")
    sum = 0
    print("diary")
    print(len(keys))
    for i in keys:
        if r.ttl(i) == -1:
            sum = sum +1
            r.delete(i)
            if sum % 1000 == 0:
                print(sum)

    sum = 0
    keys = r.keys("TS:recommend_tractate_set:device_id:*")
    print("teizi")
    print(len(keys))
    for i in keys:
        if r.ttl(i) == -1:
            r.delete(i)
            sum = sum + 1
            if sum % 1000 == 0:
                print(sum)

    sum = 0
    print("qa")
    print(len(keys))
    keys = r.keys("TS:recommend_answer_set:device_id:*")
    for i in keys:
        if r.ttl(i) == -1:
            r.delete(i)
            sum = sum + 1
            if sum % 1000 == 0:
                print(sum)


if __name__ == "__main__":
    delete_key()






















