... | ... |
@@ -1413,6 +1413,10 @@ static const char* htable_seti_doc[2] = { |
1413 | 1413 |
"Set one key in a hash table to an integer value.", |
1414 | 1414 |
0 |
1415 | 1415 |
}; |
1416 |
+static const char* htable_setex_doc[2] = { |
|
1417 |
+ "Set expire in a hash table for the item referenced by key.", |
|
1418 |
+ 0 |
|
1419 |
+}; |
|
1416 | 1420 |
static const char* htable_list_doc[2] = { |
1417 | 1421 |
"List all htables.", |
1418 | 1422 |
0 |
... | ... |
@@ -1611,6 +1615,35 @@ static void htable_rpc_seti(rpc_t* rpc, void* c) { |
1611 | 1615 |
return; |
1612 | 1616 |
} |
1613 | 1617 |
|
1618 |
+/*! \brief RPC htable.setex command to set expire for one item */ |
|
1619 |
+static void htable_rpc_setex(rpc_t* rpc, void* c) { |
|
1620 |
+ str htname, itname; |
|
1621 |
+ int exval; |
|
1622 |
+ ht_t *ht; |
|
1623 |
+ |
|
1624 |
+ if (rpc->scan(c, "SS.d", &htname, &itname, &exval) < 3) { |
|
1625 |
+ rpc->fault(c, 500, |
|
1626 |
+ "Not enough parameters (htable name, item name and expire)"); |
|
1627 |
+ return; |
|
1628 |
+ } |
|
1629 |
+ |
|
1630 |
+ /* check if htable exists */ |
|
1631 |
+ ht = ht_get_table(&htname); |
|
1632 |
+ if (!ht) { |
|
1633 |
+ rpc->fault(c, 500, "No such htable"); |
|
1634 |
+ return; |
|
1635 |
+ } |
|
1636 |
+ |
|
1637 |
+ |
|
1638 |
+ if(ki_ht_setex(NULL, &htname, &itname, exval)<0) { |
|
1639 |
+ rpc->fault(c, 500, "Failed to set the item"); |
|
1640 |
+ return; |
|
1641 |
+ } |
|
1642 |
+ |
|
1643 |
+ rpc->rpl_printf(c, "Ok"); |
|
1644 |
+ return; |
|
1645 |
+} |
|
1646 |
+ |
|
1614 | 1647 |
/*! \brief RPC htable.dump command to print content of a hash table */ |
1615 | 1648 |
static void htable_rpc_dump(rpc_t* rpc, void* c) |
1616 | 1649 |
{ |
... | ... |
@@ -1973,6 +2006,7 @@ rpc_export_t htable_rpc[] = { |
1973 | 2006 |
{"htable.get", htable_rpc_get, htable_get_doc, 0}, |
1974 | 2007 |
{"htable.sets", htable_rpc_sets, htable_sets_doc, 0}, |
1975 | 2008 |
{"htable.seti", htable_rpc_seti, htable_seti_doc, 0}, |
2009 |
+ {"htable.setex", htable_rpc_setex, htable_setex_doc, 0}, |
|
1976 | 2010 |
{"htable.listTables", htable_rpc_list, htable_list_doc, RET_ARRAY}, |
1977 | 2011 |
{"htable.reload", htable_rpc_reload, htable_reload_doc, 0}, |
1978 | 2012 |
{"htable.store", htable_rpc_store, htable_store_doc, 0}, |