MCPcopy Create free account
hub / github.com/antirez/botlib / kvGet

Function kvGet

sqlite_wrap.c:263–277  ·  view source on GitHub ↗

Get the specified key and return it as an SDS string. If the value is * expired or does not exist NULL is returned. */

Source from the content-addressed store, hash-verified

261/* Get the specified key and return it as an SDS string. If the value is
262 * expired or does not exist NULL is returned. */
263sds kvGet(sqlite3 *dbhandle,const char *key) {
264 sds value = NULL;
265 sqlRow row;
266 sqlSelect(dbhandle,&row,"SELECT expire,value FROM KeyValue WHERE key=?s",key);
267 if (sqlNextRow(&row)) {
268 int64_t expire = row.col[0].i;
269 if (expire && expire < time(NULL)) {
270 sqlQuery(dbhandle,"DELETE FROM KeyValue WHERE key=?s",key);
271 } else {
272 value = sdsnewlen(row.col[1].s,row.col[1].i);
273 }
274 }
275 sqlEnd(&row);
276 return value;
277}
278
279/* Delete the key if it exists. */
280void kvDel(sqlite3 *dbhandle, const char *key) {

Callers 1

handleRequestFunction · 0.85

Calls 5

sqlSelectFunction · 0.85
sqlNextRowFunction · 0.85
sqlQueryFunction · 0.85
sdsnewlenFunction · 0.85
sqlEndFunction · 0.85

Tested by

no test coverage detected