danielwertheim

danielwertheim


notes from a passionate developer

Share


Sections


Tags


Disclaimer

This is a personal blog. The opinions expressed here represent my own and not those of my employer, nor current or previous. All content is published "as is", without warranty of any kind and I don't take any responsibility and can't be liable for any claims, damages or other liabilities that might be caused by the content.

Aerospike for a C# developer - Day 1

Just started evaluating Aerospike as a potential key-value store. So far I really like the experience and the product. How-ever, as a C# developer, life could be a bit happier with some small adjustments from Aerospike. Let me pinpoint the ones I stumbled upon during my first hours with it. But please. Don’t get intimidated by this post. Look at the below as small tips to ease the getting started process.

The installation, even for an Ubuntu newbie like me, was a breeze. Now, for maintenance and administration, I do not know. But getting it up and running and serving requests as well as providing a nice dashboard (see below), then it’s pretty much a matter of following the great installation documentation.

Management console
aerospike-day1-02

aerospike-day1-03

First “issue”

As a C# developer of 2014, my first intuition was to check NuGet for a Aerospike package to use with e.g. C#.

aerospike-day1-00

My first thought was:

Wait a minute. I’m sure I read that they support C#… Don’t they?

Of course they have a C# client. In fact. The code is open-source on GitHub. How-ever, they also provide a ZIP-file with the client-code and samples.

aerospike-day1-01

You just open the kind of client (there are two: Normal vs Lite) that you need and then compile it. After that you have your self a reusable lib. aerospike-day1-04

Me myself, I created a personal NuGet package and hosted it in a personal feed so that I can distribute it in a 2014-timely fashion.

Second “issue”

Now, to demonstrate something I bumped into immediately. Just create a simple console application in the same solution as the AerospikeLite solution. Then add a project reference to the client and copy the code from their Introduction documentation. Change the host-IP to something that you have access to. And run. It should work (if you correct the lower-case typo client.close() –> client.Close()).

A working variation:

AerospikeClient client = new AerospikeClient("192.168.1.7", 3000);

Key key = new Key("test", "persons", "1");
Bin bin1 = new Bin("firstname", "Daniel");
Bin bin2 = new Bin("lastname", "Wertheim");

client.Put(null, key, bin1, bin2);

Record record = client.Get(null, key);

client.Close();

Now, change the namespace in the Key. That’s the first argument you pass in. Change it to: mynamespace

...
Key key = new Key("mynamespace", "persons", "1");
...

aerospike-day1-05

aerospike-day1-06

OK. I messed up. Got it. But what did I do?

Given the exception and the extra ordinary non informative message, I finally realized:

namespaces are not created on the fly and by default there’s a test namespace already created for you.

In fact, namespaces needs to be configured to exist. Well, please Aerospike. Provide a meaningful exception message.

Third “issue”

Moving on. Now, lets change the sample so that we run into the next “issue”.

...
Key key = new Key("test", "orders", "1");
Bin bin1 = new Bin("customeraccountid", "1");
Bin bin2 = new Bin("customername", "Daniel Wertheim");
...

aerospike-day1-07

aerospike-day1-08

But come-on! I just fixed it. Now what?!

Again figuring out (then finding this on other client) that bin-names can only be 14 characters long. Please Aerospike. Provide a meaningful exception message. Also, why not throw when creating the Bin instance?

Fixing the name customeraccountid –> accountid to get a working solution again:

aerospike-day1-09

Fourth “issue”

Last issue for today. When storing an int or bool and reading it back, you get a long, even though it has a constructor definingint as a value:

aerospike-day1-12

Note above, that I now also found documentation about the 14 character length constraint. Anyway, so back to the issue we were talking about and a sample:

AerospikeClient client = new AerospikeClient("192.168.1.7", 3000);

Key key = new Key("test", "myset", "issuewithint");

Bin bin1 = new Bin("myint", 1);
Bin bin2 = new Bin("mylong", (long)1);

client.Put(null, key, bin1, bin2);

Record record = client.Get(null, key);

//FAILS
//var theInt = (int)record.GetValue("myint");
var theIntAsLong = (long)record.GetValue("myint");
var theLong = (long)record.GetValue("mylong");

client.Close();

If you uncomment the line that reads back myint as int you will see something like this:

aerospike-day1-13

Summary

Again, don’t get intimidated by this post. No real “issues” as in big problems. Look at the above as small tips. I like Aerospike so far. Give it a try you to.

Cheers,

//Daniel

View Comments