Get a timeout value from an object and store it into 'timeout'. * The final timeout is always stored as milliseconds as a time where the * timeout will expire, however the parsing is performed according to * the 'unit' that can be seconds or milliseconds. * * Note that if the timeout is zero (usually from the point of view of * commands API this means no timeout) the value stored into 'timeo
| 162 | * commands API this means no timeout) the value stored into 'timeout' |
| 163 | * is zero. */ |
| 164 | int getTimeoutFromObjectOrReply(client *c, robj *object, mstime_t *timeout, int unit) { |
| 165 | long long tval; |
| 166 | long double ftval; |
| 167 | |
| 168 | if (unit == UNIT_SECONDS) { |
| 169 | if (getLongDoubleFromObjectOrReply(c,object,&ftval, |
| 170 | "timeout is not a float or out of range") != C_OK) |
| 171 | return C_ERR; |
| 172 | tval = (long long) (ftval * 1000.0); |
| 173 | } else { |
| 174 | if (getLongLongFromObjectOrReply(c,object,&tval, |
| 175 | "timeout is not an integer or out of range") != C_OK) |
| 176 | return C_ERR; |
| 177 | } |
| 178 | |
| 179 | if (tval < 0) { |
| 180 | addReplyError(c,"timeout is negative"); |
| 181 | return C_ERR; |
| 182 | } |
| 183 | |
| 184 | if (tval > 0) { |
| 185 | tval += mstime(); |
| 186 | } |
| 187 | *timeout = tval; |
| 188 | |
| 189 | return C_OK; |
| 190 | } |
no test coverage detected