Ssdb is a high-performance NoSQL database that supports rich data structures, integrates Redis's efficient, fast, and durable services, and is increasingly rich in usage scenarios.
SSDB official provides a Java Client SDK, this article describes its use.
1. First download the code from the GitHub.
Download the address: Https://github.com/ssdb/javassdb
You can see the entire SDK on 4 files, Link.java, Memorystream.java, Response.java, Ssdb.java. The author's approach is to create a new package in the project, put the 4 files in, and modify the package name in the file. This can be convenient to use, have the source can be viewed at any time.
2. Connection Ssdb
Ssdb ssdb = new Ssdb (host, port);
Ssdb.set ("name", "Archmage");
Ssdb.get ("name");
3. Other Orders
For some reason, there are some commands that are not in the official SDK function. But by looking at the source, you can see that in the Ssdb class, there is a member class called Public link, and all commands are sent through this link.request (Cmd,params). Then we can add the command function we need in the Ssdb.java. For example, here is the function of the Zrrange command that I added myself.
Added by Archmage public
Response zrrange (String key, Long offset, int limit) {
if (key = = null) {
key = "";
}
try {
Response resp = link.request ("Zrrange", Key, (New Long (offset)). ToString (), (new Integer (limit)). ToString ());
if (!resp.ok ()) {
resp.exception ();
}
for (int i = 1; i < resp.raw.size (); i + + 2) {
byte[] k = Resp.raw.get (i);
byte[] v = resp.raw.get (i + 1);
Resp.keys.add (k);
Resp.items.put (k, v);
}
Return resp;
} catch (Exception e) {
e.printstacktrace ();
return null;
}
}
//*/
Further, the return value can be encapsulated in a more refined format according to different actual requirements.