Ssdbhub.github.io
No description available
Install / Use
/learn @ssdbhub/Ssdbhub.github.ioREADME
We provide SSDB as a service.
SSDB is a high performance NoSQL database.
SSDBHub provides one click solution for provisioning of highly available SSDB cluster, which may be accessed directly via SSDB or Redis clients.
SSDB clients are available in many languages. Below there are basic code samples of how to connect to database, authenticate the connection and start to send commands to SSDB using the following languages:
C++, C#, Java, Python, Node.js, Ruby, PHP, Go.
As mentioned above, it's possible to communicate with SSDB using Redis clients. Below there is a list of supported Redis commands and how they map to SSDB.
Heroku Platform
- Warning! Heroku SSDBHub add-on is currently at beta stage, therefore there might be changes to this document.
Provisioning add-on
SSDBHub plugin can be attached to a Heroku application via the CLI:
Here the list of all available plans.
$ heroku addons:create ssdb
-----> Adding ssdb to sharp-mountain-4005... done, v18 (free)
Once SSDB is added to your app, the following variables will be added to environment configuration:
SSDB_HOST
SSDB_PORT
SSDB_URL
SSDB_PASSWORD
These should be used to access the newly provisioned SSDB instance.
Configuration variables can be confirmed using the heroku config:get command.
$ heroku config:get SSDB_HOST
172.217.18.14
$ heroku config:get SSDB_PORT
32612
$ heroku config:get SSDB_URL
http://172.217.18.14:32612
$ heroku config:get SSDB_PASSWORD
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJoZWxsbyI6InRlc3QifQ..
After installing SSDBHub the application should be configured to fully integrate with the add-on. Please note that SSDB_URL is only the combination of SSDB_HOST and SSDB_PORT. Some clients will require both of them separate, others will use full url as a connection string.
Local setup
Environment setup
After provisioning the add-on it's necessary to locally replicate the config vars so your development environment operate against the service.
Use the Heroku Local command-line tool to configure, run and manage process
types specified in your app's Procfile.
Heroku Local reads configuration variables from a .env file.
To view all of your app's config vars, type heroku config.
Use the following command for each value you want to add to your .env file.
$ heroku config:get SSDB_HOST -s >> .env
$ heroku config:get SSDB_PORT -s >> .env
$ heroku config:get SSDB_PASSWORD -s >> .env
$ heroku config:get SSDB_URL -s >> .env
- Credentials and other sensitive configuration values should not be committed to source-control.
In Git exclude the
.envfile with:echo .env >> .gitignore.
For more information, see Heroku Local article.
Using SSDB with Different Languages
As already mentioned above SSDB has many client libraries in different programming languages. Below are couple of examples on how you can apply them.
Using with Java
Available clients
Package | Author | Repository | Description --- | --- | --- | --- | official ★ | ideawu | Repository | This is the official client ssdb4j | nutzam | Repository | Yet another SSDB client for Java another ssdb4j | jbakwd | Repository | hydrogen-ssdb | yiding-he | Repository | Supports client-side load-balance
The following example uses official Java client, which needs to be imported within the application.
import com.udpwork.ssdb.*;
Then the client library should be created using environment variables, which were discussed previously.
String host = System.getenv("SSDB_HOST");
String port = System.getenv("SSDB_PORT");
SSDB ssdb = new SSDB(host, Integer.parseInt(port));
SSDBHub enforces authentication on SSDB instance. After the client is created, it should be authenticated with the password which is returned in SSDB_PASSWORD configuration variable.
String pass = System.getenv("SSDB_PASSWORD");
Response resp = ssdb.request("auth", pass);
if(!resp.ok()){
resp.exception();
}
Now when client is authenticated it's ready to be used
ssdb.set("mykey", "myvalue");
byte[] val = ssdb.get("myvalue");
Using with Python
Available clients
Package | Author | Repository | Description --- | --- | --- | --- | built-in ★ | ideawu | Repository | This is the official client pyssdb | ifduyue | Repository | A SSDB Client Library for Python ssdb-py | wrongwaycn | Repository | SSDB Python Client like Redis-Py ssdb.py | hit9 | Repository | SSDB Python Client Library by hit9
For this example the ssdb-py client is use. Before using the package it should be installed as follows:
$ pip install ssdb
Application will need to import the library
import ssdb
Then the client should be created using environment variables.
import os
host = os.env["SSDB_HOST"]
port = os.env["SSDB_PORT"]
ssdb = ssdb.SSDB(host, port)
SSDBHub enforces authentication on SSDB instance. After the client is created, it should be authenticated with the password which is returned in SSDB_PASSWORD configuration variable.
pass = os.env["SSDB_PASSWORD"];
resp = ssdb.execute_command("auth", pass);
if resp[0] != "ok":
raise Exception("Invalid Password")
Now when client is authenticated it's ready to be used
ssdb.set("mykey", "myvalue");
res = ssdb.get("mykey");
Using with Node
Available clients
Package | Author | Repository | Description --- | --- | --- | --- | official ★ | ideawu | Repository | This is the official client node-ssdb by @hit9 | hit9 | Repository | node-ssdb by @hit9
For this example the node-ssdb library is use. Before using the package it should be installed
$ npm install ssdb
Application will need to import the library
var ssdb = require('ssdb');
Then the connection pool should be created using environment variables.
SSDBHub enforces authentication on SSDB instance. After the client is created, it should be authenticated with the password which is returned in SSDB_PASSWORD configuration variable.
var host = process.env.SSDB_HOST
var port = process.env.SSDB_PORT
var pass = process.env.SSDB_PASSWORD
var pool = ssdb.createPool({
host: host,
port: port,
auth: pass
});
Now when connection pool is created it's ready to be used.
pool.acquire().set('key', 'val', function(err, data) {
if (err && err instanceof ssdb.SSDBError)
throw err; // ssdb error
});
Using with Go
Available clients
Package | Author | Repository | Description --- | --- | --- | --- | official ★ | ideawu | Repository | This is the official client hissdb | Eryx | Repository | hissdb in lessos/lessgo, supports connection pool. gossdb | seefan | Repository | From the official client derived from the client, supports the connection pool and set, get, habits and most client consistent.
For this example the hissdb library is use. Application will need to import the library
package main
import (
"fmt"
"github.com/lessos/lessgo/data/hissdb"
)
Then the connection should be created using environment variables.
SSDBHub enforces authentication on SSDB instance. After the client is created, it should be authenticated with the password which is returned in SSDB_PASSWORD configuration variable.
import os
import strconv
func main() {
host := os.Getenv("SSDB_HOST")
port := os.Getenv("SSDB_PORT")
auth := os.Getenv("SSDB_PASSWORD")
conn, err := hissdb.NewConnector(hissdb.Config{
Host: host,
Port: strconv.ParseInt(port),
Auth: auth,
Timeout: 3, // timeout in second, default to 10
MaxConn: 10, // max connection number, default to 1
})
if err != nil {
fmt.Println("Connect Error:", err)
return
}
defer conn.Close()
Now when connection is created it's ready to be used.
conn.Cmd("set", "mykey", "myvalue")
if rs := conn.Cmd("get", "mykey"); rs.State == "ok" {
fmt.Println("get OK\n\t", rs.String())
}
}
Using with Ruby
Available clients
Package | Author | Repository | Description --- | --- | --- | --- | ssdb-rb | bsm | Repository | Ruby client library for SSDB
Application will need to import the library
gem install ssdb
Then create the connection using environment variables.
require "ssdb"
ssdb = SSDB.new url: ENV['SSDB_URL']
SSDBHub enforces authentication on SSDB instance. After the client is created, it should be authenticated with the password which is returned in SSDB_PASSWORD configuration variable.
ssdb.perform("auth", ENV['SSDB_PASSWORD'])
Now when connection is created it's ready to be used.
ssdb.set("mykey", "myvalue")
# => true
ssdb.get("mykey")
# => "myvalue"
Using with PHP
Available clients
