aerospike / aerospike-client-rust

Rust client for the Aerospike database
https://www.aerospike.com/
Other
82 stars 26 forks source link

Client Sharing #101

Closed abhilashg1 closed 1 year ago

abhilashg1 commented 3 years ago

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

khaf commented 3 years ago

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.

abhilashg1 commented 3 years ago

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.

jonas32 commented 3 years ago

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.

khaf commented 3 years ago

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 .