Couchbase C SDK 的 Hello World 示例中的键和值在做什么?
What is the key and value doing in the Couchbase C SDK’s Hello World example?
在此link中:https://docs.couchbase.com/c-sdk/current/hello-world/start-using-sdk.html#hello-couchbase
我看到下面这个使用 Couchbase SDK 的代码示例,但是键和值指针代表什么? key应该是文件名吗?
static void store_callback(lcb_INSTANCE *instance, int cbtype, const lcb_RESPSTORE *resp)
{
const char *key;
size_t nkey;
uint64_t cas;
lcb_respstore_key(resp, &key, &nkey);
lcb_respstore_cas(resp, &cas);
printf(“status: %s, key: %.*s, CAS: 0x%” PRIx64 “\n”,
lcb_strerror_short(lcb_respstore_status(resp)), (int)nkey, key, cas);
}
lcb_install_callback3(instance, LCB_CALLBACK_STORE, (lcb_RESPCALLBACK)store_callback);
lcb_STATUS rc;
lcb_CMDSTORE *cmd;
const char *collection = NULL, *scope = NULL;
size_t collection_len = 0, scope_len = 0;
const char *key = “my-document”;
const char *value = “{“name”: “mike”}”;
rc = lcb_cmdstore_create(&cmd, LCB_STORE_UPSERT);
rc = lcb_cmdstore_collection(cmd, scope, scope_len, collection, collection_len);
rc = lcb_cmdstore_key(cmd, key, strlen(key));
rc = lcb_cmdstore_value(cmd, value, strlen(value));
rc = lcb_store(instance, NULL, cmd);
rc = lcb_cmdstore_destroy(cmd);
rc = lcb_wait(instance);
在 Couchbase 中,本身并没有“文档名称”。 Couchbase 是 key/value 数据库,但是当您使用 JSON 时(正如大多数用户所做的那样),它会变成一个文档数据库。
因此,如果您指的是:
const char *key = "my-document";
const char *value = "{\"name\": \"mike\"}";
这是指一个文档,其键为“my-document”,JSON 值为{"name": "mike"}
。这是 Couchbase UI 的一些屏幕截图,显示了它的外观:
在此link中:https://docs.couchbase.com/c-sdk/current/hello-world/start-using-sdk.html#hello-couchbase
我看到下面这个使用 Couchbase SDK 的代码示例,但是键和值指针代表什么? key应该是文件名吗?
static void store_callback(lcb_INSTANCE *instance, int cbtype, const lcb_RESPSTORE *resp)
{
const char *key;
size_t nkey;
uint64_t cas;
lcb_respstore_key(resp, &key, &nkey);
lcb_respstore_cas(resp, &cas);
printf(“status: %s, key: %.*s, CAS: 0x%” PRIx64 “\n”,
lcb_strerror_short(lcb_respstore_status(resp)), (int)nkey, key, cas);
}
lcb_install_callback3(instance, LCB_CALLBACK_STORE, (lcb_RESPCALLBACK)store_callback);
lcb_STATUS rc;
lcb_CMDSTORE *cmd;
const char *collection = NULL, *scope = NULL;
size_t collection_len = 0, scope_len = 0;
const char *key = “my-document”;
const char *value = “{“name”: “mike”}”;
rc = lcb_cmdstore_create(&cmd, LCB_STORE_UPSERT);
rc = lcb_cmdstore_collection(cmd, scope, scope_len, collection, collection_len);
rc = lcb_cmdstore_key(cmd, key, strlen(key));
rc = lcb_cmdstore_value(cmd, value, strlen(value));
rc = lcb_store(instance, NULL, cmd);
rc = lcb_cmdstore_destroy(cmd);
rc = lcb_wait(instance);
在 Couchbase 中,本身并没有“文档名称”。 Couchbase 是 key/value 数据库,但是当您使用 JSON 时(正如大多数用户所做的那样),它会变成一个文档数据库。
因此,如果您指的是:
const char *key = "my-document";
const char *value = "{\"name\": \"mike\"}";
这是指一个文档,其键为“my-document”,JSON 值为{"name": "mike"}
。这是 Couchbase UI 的一些屏幕截图,显示了它的外观: