MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / getTimeoutFromObjectOrReply

Function getTimeoutFromObjectOrReply

src/timeout.cpp:166–192  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

164 * commands API this means no timeout) the value stored into 'timeout'
165 * is zero. */
166int 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}

Callers 7

waitCommandFunction · 0.85
xreadCommandFunction · 0.85
clientCommandFunction · 0.85
blmoveCommandFunction · 0.85
brpoplpushCommandFunction · 0.85

Calls 4

addReplyErrorFunction · 0.85
mstimeFunction · 0.70

Tested by

no test coverage detected