Java SSDB Connection operation

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.