Name

lcb_create_compat — Create instance

Synopsis

cc [ flag … ] file… -lcouchbase [ library … ]

#include <libcouchbase/couchbase.h>
lcb_error_t lcb_create_compat(lcb_compat_t type,
                              const void *specific,
                              lcb_t *instance,
                              struct lcb_io_opt_st *io);

DESCRIPTION

lcb_create_compat creates an instance of libcouchbase with special configuration options.

The type parameter specifices the type of compatibility backend to use. The following types are defined:

+LCB_MEMCACHED_CLUSTER+     Disable the REST configuration
                            protocol and connect to a fixed
                            list of memcached servers.
+LCB_CACHED_CONFIG+         Use a cached copy of the cluster
                            topology to bypass the REST
                            bootstrapping.

The content of the specific parameter depends on the type parameter.

See lcb_create() for more information about the instance and io parameter.

LCB_MEMCACHED_CLUSTER

For LCB_MEMCACHED_CLUSTER the specific parameter points to a struct lcb_memcached_st:

struct lcb_memcached_st {
    const char *serverlist;
    const char *username;
    const char *password;
};

The serverlist is a list of server separated with a semicolon. username and password may be specified to use SASL authentication to the memcached cluster.

LCB_CACHED_CONFIG

For LCB_MEMCACHED_CLUSTER the specific parameter points to a struct lcb_cached_config_st:

struct lcb_cached_config_st {
    struct lcb_create_st createopt;
    const char *cachefile;
};

See lcb_create() for a description of the internals of the createopt structure. The information in the createopt structure is used if the cachefile is missing or stale. The cachefile is used to specify a file (absolute or relative) where the cluster topology is stored. If the file exists the entire bootstrapping logic is skipped during startup, and delayed until an error is returned from the cluster indicating that the information in the cache is stale.

RETURN VALUES

lcb_create() returns the LCB_SUCCESS on success, or a specific error code upon failure. See lcb_strerror(3couchbase) for more information.

EXAMPLES

Example 1: Create an instance that may be used with a memcached cluster.

struct lcb_memcached_st memcached;
lcb_t instance;
lcb_error_t err;
memset(&memcached, 0, sizeof(memcached));
memcached.serverlist = "localhost:11211;localhost:11212";
err = lcb_create_compat(LCB_MEMCACHED_CLUSTER, &memcached,
                        &instance, NULL);
if (err != LCB_SUCCESS) {
    ... error ...
}

Example 2: Create an instance that uses configuration caching:

lcb_t instance;
lcb_error_t err;
struct lcb_cached_config_st config;
memset(&config, 0, sizeof(config));
config.createopt.version = 1;
config.createopt.v.v1.host = "host1";
config.createopt.v.v1.user = "mybucket";
config.createopt.v.v1.passwd = "secret";
config.createopt.v.v1.bucket = "mybucket";
config.cachefile = "/var/tmp/couchbase-config-cache";
err = lcb_create_compat(LCB_CACHED_CONFIG, &config,
                        &instance, NULL);
if (err != LCB_SUCCESS) {
    ... error ...
}

ATTRIBUTES

See lcb_attributes(5) for descriptions of the following attributes:

ATTRIBUTE TYPE ATTRIBUTE VALUE

Interface Stability

Committed

MT-Level

MT-Safe

COPYRIGHT

Copyright 2010-2013 Couchbase, Inc.

SEE ALSO

Learn more at http://www.couchbase.com/communities/c.

libcouchbase(3lib), lcb_create(3couchbase), lcb_create_io_ops(3couchbase), lcb_attributes(5)