import os, redis, json, time from configure import REDIS_CHANNEL def publish(number): redis_host = os.getenv('REDIS_HOST', '127.0.0.1') redis_password = os.getenv('REDIS_PASSWORD', '123456') r = redis.Redis(host=redis_host, port=6379, password=redis_password, db=0) r.publish(REDIS_CHANNEL, json.dumps({'filename':'a.txt', 'data':str(number)})) n = 0 while True: publish(n) time.sleep(3) n += 1