import redis
def data(time, light, temperature):
redis_conn.rpush("pico:timeticks", time)
redis_conn.hset("pico:light", mapping={time: light})
redis_conn.hset("pico:temperature", mapping={time: temperature})
# Connect to Redis
redis_conn = redis.Redis.from_url('rediss://xxxxx:6379')
# Generate and store data
for i in range(1, 5):
time = f"2024-0-01-01-0{i}-00"
light = f"{i}0000"
temperature = f"2{i}"
data(time, light, distance)
# Retrieve and print data from Redis
time_list = [item.decode() for item in redis_conn.lrange("pico:timeticks", 0, 4)]
for time in time_list:
light = redis_conn.hget("pico:light", time)
temperature = redis_conn.hget("pico:temperature", time)
print(time, light, temperature)
print("======================")