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
| 164 | * commands API this means no timeout) the value stored into 'timeout' |
| 165 | * is zero. */ |
| 166 | int getTimeoutFromObjectOrReply(client *c, robj *object, mstime_t *timeout, int unit) { |
| 167 | long long tval; |
| 168 | long double ftval; |
| 169 | |
| 170 | if (unit == UNIT_SECONDS) { |
| 171 | if (getLongDoubleFromObjectOrReply(c,object,&ftval, |
| 172 | "timeout is not a float or out of range") != C_OK) |
| 173 | return C_ERR; |
| 174 | tval = (long long) (ftval * 1000.0); |
| 175 | } else { |
| 176 | if (getLongLongFromObjectOrReply(c,object,&tval, |
| 177 | "timeout is not an integer or out of range") != C_OK) |
| 178 | return C_ERR; |
| 179 | } |
| 180 | |
| 181 | if (tval < 0) { |
| 182 | addReplyError(c,"timeout is negative"); |
| 183 | return C_ERR; |
| 184 | } |
| 185 | |
| 186 | if (tval > 0) { |
| 187 | tval += mstime(); |
| 188 | } |
| 189 | *timeout = tval; |
| 190 | |
| 191 | return C_OK; |
| 192 | } |
no test coverage detected