Aerospike C client manual --- establish a connection to the aerospike Client

Source: Internet
Author: User
Tags aerospike

Aerospike C client manual --- establish a connection to the aerospike Client


C client function library

Establish a connection

The Aerospike object describes a cluster. To connect to a cluster, configure an aerospike object.

Configure the client

To configure the client, you must provide an as_config object that is initialized and filled with configuration information.

First, use as_config_init () to initialize as_config by default:

as_config config;as_config_init(&config);

After the as_config Initialization is complete, fill it with application-specific settings.

At least one server address must be configured for the client as seed. The client will try to connect to each seed host until the connection is successful.

config.hosts[0] = { .addr = "127.0.0.1", .port = 3000 };
Initialize the client

To connect to the cluster, first use the as_config configuration object created earlier to initialize an aerospike client object.

aerospike as;aerospike_init(&as, &config);

After the aerospike_init () function is successfully executed, the aerospike client object after Initialization is completed is returned. Otherwise, NULL is returned ).

Establish a connection

Now, use the initialized aerospike client object to connect to the cluster. The aerospike_connect () function requires an as_error object to return error information:

as_error err;if (aerospike_connect(&as, &err) != AEROSPIKE_OK) {    fprintf(stderr, "err(%d) %s at [%s:%d]\n", err.code, err.message, err.file, err.line);}

The return code of the function is consistent with the value of err. code. If the return code is not AEROSPIKE_ OK, it indicates that an error has occurred. You can obtain more information by checking the err Object.

An aerospike client stores the cluster status and maintains a connection pool with the cluster. The same aerospike client object can be reused by applications to complete database operations on a given cluster.

To connect an application to multiple Aerospike clusters, the application must create multiple aerospike client objects, each of which is connected to different clusters.

Close connection

When you no longer need a client to connect to a cluster, use aerospike_close () to close the connection:

as_error err;if (aerospike_close(&as, &err) != AEROSPIKE_OK) {    fprintf(stderr, "err(%d) %s at [%s:%d]\n", err.code, err.message, err.file, err.line);}
Clear

When the client no longer needs it, use aerospike_destroy () to destroy the client object and release its occupied resources:

aerospike_destroy(&as);

Link: http://www.aerospike.com/docs/client/c/usage/connect/ Translated by: Q  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.