Get the specified key and return it as an SDS string. If the value is * expired or does not exist NULL is returned. */
| 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. */ |
| 263 | sds 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. */ |
| 280 | void kvDel(sqlite3 *dbhandle, const char *key) { |
no test coverage detected