static void do_memcached_flush(INTERNAL_FUNCTION_PARAMETERS, int oo, php_couchbase_res *res) { lcb_error_t retval; lcb_error_t cberr = LCB_SUCCESS; php_couchbase_ctx *ctx; lcb_flush_cmd_t cmd; const lcb_flush_cmd_t *const commands[] = { &cmd }; lcb_t instance; instance = res->handle; memset(&cmd, 0, sizeof(cmd)); lcb_set_flush_callback(instance, memcached_flush_callback); retval = lcb_flush(instance, (const void *)&cberr, 1, commands); if (retval == LCB_SUCCESS) { retval = cberr; } res->rc = retval; if (retval == LCB_SUCCESS) { RETURN_TRUE; } else { char errmsg[256]; sprintf(errmsg, "Failed to flush bucket: %s", lcb_strerror(instance, retval)); couchbase_report_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, oo, cb_lcb_exception, errmsg); } }
/*opaque_t*/ int couchdb_create(void) { struct lcb_create_st create_opt; struct lcb_create_io_ops_st io_opts; lcb_error_t ret; io_opts.version = 0; io_opts.v.v0.type = LCB_IO_OPS_DEFAULT; io_opts.v.v0.cookie = NULL; ret = lcb_create_io_ops(&create_opt.v.v0.io, &io_opts); if (ret != LCB_SUCCESS) { syslog(LOG_ERR, "%s:Failed to create IO instance: %s\n", __FUNCTION__, lcb_strerror(NULL, ret)); return -1; } memset(&create_opt, 0, sizeof(struct lcb_create_st)); create_opt.v.v0.host = "127.0.0.1:8091"; create_opt.v.v0.user = "******"; create_opt.v.v0.passwd = "123456"; create_opt.v.v0.bucket = "default"; ret = lcb_create(&couchdb_handle, &create_opt); if (ret != LCB_SUCCESS) { COUCHDB_LOG("Error creating couchbase DB instance\n"); return (-1); } /* Setup the Global variables */ value = (void *) malloc(DATA_SIZE * sizeof(char)); if (NULL == value) { syslog(LOG_ERR, "%s: Failed to allocate memory for value\n", __FUNCTION__); return -ENOMEM; } pthread_rwlock_init(&db_rwlock, NULL); /* Once a valid handle is obtained, set up all the callbacks */ lcb_set_error_callback(couchdb_handle, error_cb); lcb_set_get_callback(couchdb_handle, get_cb); lcb_set_store_callback(couchdb_handle, set_cb); lcb_set_flush_callback(couchdb_handle, flush_cb); lcb_set_remove_callback(couchdb_handle, remove_cb); /* Now connect to the cluster having the server node on the "host" ip */ ret = lcb_connect(couchdb_handle); if (ret != LCB_SUCCESS) { COUCHDB_LOG("Error connecting to the cluster\n"); return (-1); } /* Since the couchbase APIs are all asynchronous calls, we need to block the thread until the connect succeeds */ lcb_wait(couchdb_handle); return (0); }