#include <unistd.h>
#include <pthread.h>
#include <string.h>
#include <sys/types.h>
{
const char *key;
size_t nkey;
lcb_respget_key(resp, &key, &nkey);
(void)instance;
(void)cbtype;
}
typedef struct {
pthread_mutex_t mutex;
} my_CTX;
static void *thread_func(void *arg)
{
my_CTX *ctx = arg;
const char *key = "key";
lcb_CMDGET *cmd = NULL;
lcb_cmdget_create(&cmd);
lcb_cmdget_key(cmd, key, strlen(key));
pthread_mutex_lock(&ctx->mutex);
lcb_STATUS rc = lcb_get(ctx->instance, NULL, cmd);
lcb_cmdget_destroy(cmd);
if (rc != LCB_SUCCESS) {
fprintf(stderr,
"Could not schedule GET \"%.*s\", %s\n", (
int)strlen(key), key,
lcb_strerror_short(rc));
} else {
}
pthread_mutex_unlock(&ctx->mutex);
return NULL;
}
int main(int argc, const char *argv[])
{
#define number_of_threads 10
const char *connection_string = (argc > 1) ? argv[1] : "couchbase://127.0.0.1/default";
const char *username = (argc > 2) ? argv[2] : "Administrator";
const char *password = (argc > 3) ? argv[3] : "password";
pthread_t thrs[number_of_threads];
my_CTX ctx;
pthread_mutex_init(&ctx.mutex, NULL);
lcb_CREATEOPTS *options = NULL;
lcb_createopts_connstr(options, connection_string, strlen(connection_string));
lcb_createopts_credentials(options, username, strlen(username), password, strlen(password));
for (int ii = 0; ii < number_of_threads; ii++) {
pthread_create(&thrs[ii], NULL, thread_func, &ctx);
}
for (int ii = 0; ii < number_of_threads; ii++) {
void *ign;
pthread_join(thrs[ii], &ign);
}
return 0;
}
Main header file for Couchbase.
void lcb_destroy(lcb_INSTANCE *instance)
Destroy (and release all allocated resources) an instance of lcb.
LCB_INTERNAL_API const char * lcb_strerror_short(lcb_STATUS error)
Get a shorter textual description of an error message.
lcb_STATUS
Error codes returned by the library.
Definition error.h:213
struct lcb_RESPGET_ lcb_RESPGET
Command for retrieving a single item.
Definition couchbase.h:687
lcb_STATUS lcb_create(lcb_INSTANCE **instance, const lcb_CREATEOPTS *options)
Create an instance of lcb.
struct lcb_st lcb_INSTANCE
Library handle representing a connection to a cluster and its data buckets.
Definition couchbase.h:35
lcb_STATUS lcb_connect(lcb_INSTANCE *instance)
Schedule the initial connection This function will schedule the initial connection for the handle.
@ LCB_TYPE_BUCKET
Handle for data access (default)
Definition couchbase.h:256
lcb_RESPCALLBACK lcb_install_callback(lcb_INSTANCE *instance, int cbtype, lcb_RESPCALLBACK cb)
void(* lcb_RESPCALLBACK)(lcb_INSTANCE *instance, int cbtype, const lcb_RESPBASE *resp)
Callback invoked for responses.
Definition couchbase.h:554
@ LCB_CALLBACK_GET
lcb_get()
Definition couchbase.h:471
lcb_STATUS lcb_wait(lcb_INSTANCE *instance, lcb_WAITFLAGS flags)
Wait for completion of scheduled operations.
@ LCB_WAIT_DEFAULT
Behave like the old lcb_wait()
Definition couchbase.h:1861