aerospike-client-rust icon indicating copy to clipboard operation
aerospike-client-rust copied to clipboard

Client Sharing

Open abhilashg1 opened this issue 3 years ago • 4 comments

Hi team,

We are new to Rust and we are trying something to achieve here, like other languages, we want to create a client and share the same with many parts of our code.

We cannot find a simple way to share the client with other functions in the code, as we don't find a sample anywhere, it would be helpful if anyone gives a simple example.

Thanks

abhilashg1 avatar Apr 02 '21 13:04 abhilashg1

Sorry for the late reply. While we don't have any concrete examples, the tests should provide a solid base for learning the library. Let me know if I can help you any further.

khaf avatar Apr 09 '21 12:04 khaf

Really looking for a pool handler or any inbuilt support for handling connection reusability as we cannot create new connection to Aerospike for each inbound request.

abhilashg1 avatar Apr 10 '21 11:04 abhilashg1

The way you need to pass around instances like the Aerospike Client is a bit different in rust than most other languages would handle that. You have to pass the reference of the instance. The general way to pass around the Client would probably be Arc. Using this, you can use it in requests without creating a new one each time. Check this: https://doc.rust-lang.org/std/sync/struct.Arc.html When you talk about requests, i assume you are talking about a web API and probably actix. For the actix example, you would wrap the Client instance with Arc and then pass it to the Server instance with the "data" function of the actix server instance.

If you need any more info, please provide some more information on your app. Its hard to guess what would fit for your case without that.

jonas32 avatar Apr 12 '21 01:04 jonas32

Since it wasn't directly addressed in @jonas32 answer, the connections are pooled automatically inside the client. Just connect to the database, and share that connection within your code as explained by @jonas32 .

khaf avatar Apr 12 '21 06:04 khaf