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.
As a C# developer of 2014, my first intuition was to check NuGet for a Aerospike package to use with e.g. C#.
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.
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.
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.
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
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:
... Key key = new Key("mynamespace", "persons", "1"); ...
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
testnamespace already created for you.
In fact, namespaces needs to be configured to exist. Well, please Aerospike. Provide a meaningful exception message.
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"); ...
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
Fixing the name
accountid to get a working solution again:
Last issue for today. When storing an
bool and reading it back, you get a
long, even though it has a constructor defining
int as a value:
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
int you will see something like this:
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.