GWAN Key-Value persistent store

二次信任 提交于 2019-12-07 19:24:49

问题


I want to use the GWAN API Key-Value to record and read a number of data (in a multi-threaded way). The problem is that my recordings are only available on the current page and therefore can not be used on my other pages.

Can you show me an example or explain how to create a persistent KV store (which will be accessible on all my subdomains) ?

Here is an example that I currently use:

kv_t store;
kv_init(&store, "users", 10, 0, 0, 0);

kv_item item;
item.key = "pierre";
item.klen = sizeof("pierre") - 1;
item.val = "pierre@example.com";
item.flags = 0;
kv_add(&store, &item);

char *p = kv_get(&store, "pierre", sizeof("pierre") - 1);
xbuf_xcat(get_reply(argv), "<br>pierre's email address: %s<br>", p);

but is not persistent.


回答1:


As G-WAN scripts are compiled and linked independently, 'global' variables are 'static' (to each script) rather than available for all scripts.

So, you have to attach the KV store to a persistent pointer. G-WAN offers persistent pointers with different scopes:

US_REQUEST_DATA = 200, // Request-wide pointer
US_HANDLER_DATA,       // Listener-wide pointer
US_VHOST_DATA,         // Virtual-Host-wide pointer
US_SERVER_DATA,        // global pointer (for maintenance script)

There are several G-WAN script examples demonstrating how to do that:

http://gwan.ch/source/persistence.c http://gwan.ch/source/stream1.c http://gwan.ch/source/forum.c etc.



来源:https://stackoverflow.com/questions/23259134/gwan-key-value-persistent-store

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!