金桂冠关键值的持久化存储 [英] GWAN Key-Value persistent store
问题描述
我想使用的API金桂冠键值来记录和读取的数据数(在一个多线程的方式)。问题是,我的录音是仅在当前页面上提供,因此不能在我的其它网页上。
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.
您可以告诉我一个例子或解释如何创建一个持久KV存储(这将是对我的所有子域访问)?
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);
但不是持久的。
推荐答案
由于G-WAN脚本编译和独立的联系,全球变量静态(为每个脚本),而不是适用于所有的脚本。
As G-WAN scripts are compiled and linked independently, 'global' variables are 'static' (to each script) rather than available for all scripts.
所以,你必须将KV存储连接到一个持续的指针。 G-WAN提供永久指针,不同的范围的:
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)
有几个G-WAN脚本示例演示如何做到这一点:
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
等等。
这篇关于金桂冠关键值的持久化存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!