remicaumette / esp8266-redis

An Arduino library for Redis that works on ESP8266.
24 stars 11 forks source link

support setNoDelay and setTimeout for WiFi connection #4

Closed robertoostenveld closed 6 years ago

robertoostenveld commented 6 years ago

I noticed when doing

redis.set("foo", "1");
delay(1000);
redis.set("foo", "2");
delay(1000);
redis.set("foo", "3");
delay(1000);
redis.set("foo", "4");
delay(1000);

that it would take some 5 seconds between each of the 1, 2, 3, 4 appearing in my database (using "redis-cli monitor").

I first thought it was due to the Angle algorithm, hence I implemented the http://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/client-class.html. That did not solve it (but it is in this PR, as it might be useful for others).

I traced the problem further down to the "conn.readStringUntil". Upon the first read attempt, there is no data yet. The read command then seems to pause for 5 seconds before trying again. This can be solved using the https://www.arduino.cc/en/Reference/StreamSetTimeout command.

This PR allows for

redis.setNoDelay(bool)
redis.setTimeout(long)

which both should be called prior to redis.begin()

remicaumette commented 6 years ago

I will merge it. Thanks for your contribution 😄