This is the SSDB client and command-line tool.
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 37 commits ahead, 14 commits behind ssdb:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
cmd/ssdb
example
term
vendor
.gitignore
.travis.yml
Dockerfile
Gopkg.lock
Gopkg.toml
LICENSE
README.md
README_cn.md
build_all.bash
client.go
cmd_hash.go
cmd_kv.go
cmd_list.go
cmd_server.go
cmd_sorted_set.go
conn.go
do.go
option.go
result.go
value.go

README.md

SSDB client for golang

This is the SSDB client and command-line tool.

Go Report Card GoDoc GitHub license

example

package main

import (
	"fmt"

	"github.com/wzshiming/ssdb"
)

func main() {
	db, err := ssdb.Connect(
		ssdb.Addr("127.0.0.1:8888"),
		ssdb.Auth("password"),
		// or ssdb.URL("ssdb://127.0.0.1:8888?Auth=password"),
	)
	if err != nil {
		fmt.Println(err)
		return
	}

	err = db.Set("a", "xxx")
	if err != nil {
		fmt.Println(err)
		return
	}

	val, err := db.Get("a")
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(val)

	err = db.Del("a")
	if err != nil {
		fmt.Println(err)
		return
	}

	val, err = db.Get("a")
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(val)

	err = db.ZSet("z", "a", 3)
	if err != nil {
		fmt.Println(err)
		return
	}

	err = db.MultiZSet("z", map[string]int64{
		"b": -1,
		"c": 5,
		"d": 3,
	})
	if err != nil {
		fmt.Println(err)
		return
	}

	resp, err := db.ZRange("z", 0, 10)
	if err != nil {
		fmt.Println(err)
		return
	}

	for k, v := range resp {
		fmt.Printf("  %v : %v\n", k, v)
	}

	return
}

Command-line tool


go get -u -v github.com/wzshiming/ssdb/cmd/ssdb

ssdb -p password 127.0.0.1:8888

SSDB (cli) - ssdb command line tool.
Copyright (c) 2018 github.com/wzshiming

        'help' for help, 'quit' to quit.

ssdb-server 1.9.4
SSDB 127.0.0.1:8888 > set a xxx

1
1 result(s) (3ms)
SSDB 127.0.0.1:8888 > get a

xxx
1 result(s) (3ms)
SSDB 127.0.0.1:8888 > del a

1
1 result(s) (5ms)
SSDB 127.0.0.1:8888 > get a

not found
(4ms)
SSDB 127.0.0.1:8888 > zset z a 3

0
1 result(s) (3ms)
SSDB 127.0.0.1:8888 > multi_zset z b -1 c 5 d 3

0
1 result(s) (5ms)
SSDB 127.0.0.1:8888 > zrange z 0 10

key value
--- -----
b   -1
a   3
d   3
c   5
4 result(s) (28ms)

API Support

Official Documents
API Documents

  • Server
    • auth password - Authenticate the connection.
    • dbsize - Return the approximate size of the database.
    • flushdb [type] - Delete all data in ssdb server.
    • info [opt] - Return the information of server.
    • slaveof id host port [auth last_seq last_key] - Start a replication slave.
  • IP Filter
  • Key Value
    • set key value - Set the value of the key.
    • setx key value ttl - Set the value of the key, with a time to live.
    • setnx key value - Set the string value in argument as value of the key only if the key doesn"t exist.
    • expire key ttl - Set the time left to live in seconds, only for keys of KV type.
    • ttl key - Returns the time left to live in seconds, only for keys of KV type.
    • get key - Get the value related to the specified key
    • getset key value - Sets a value and returns the previous entry at that key.
    • del key - Delete specified key.
    • incr key [num] - Increment the number stored at key by num.
    • exists key - Verify if the specified key exists.
    • getbit key offset - Return a single bit out of a string.
    • setbit key offset val - Changes a single bit of a string. The string is auto expanded.
    • bitcount key [start] [end] - Count the number of set bits (population counting) in part of a string.
    • countbit key start size - Count the number of set bits (population counting) in part of a string.
    • substr key start size - Return part of a string.
    • strlen key - Return the number of bytes of a string.
    • keys key_start key_end limit - List keys in range (key_start, key_end].
    • rkeys key_start key_end limit - List keys in range (key_start, key_end], in reverse order.
    • scan key_start key_end limit - List key-value pairs with keys in range (key_start, key_end].
    • rscan key_start key_end limit - List key-value pairs with keys in range (key_start, key_end], in reverse order.
    • multi_set key1 value1 key2 value2 ... - Set multiple key-value pairs(kvs) in one method call.
    • multi_get key1 key2 ... - Get the values related to the specified multiple keys
    • multi_del key1 key2 ... - Delete specified multiple keys.
  • Hashmap
    • hset name key value - Set the string value in argument as value of the key of a hashmap.
    • hget name key - Get the value related to the specified key of a hashmap
    • hdel name key - Delete specified key in a hashmap.
    • hincr name key [num] - Increment the number stored at key in a hashmap by num
    • hexists name key - Verify if the specified key exists in a hashmap.
    • hsize name - Return the number of key-value pairs in the hashmap.
    • hlist name_start name_end limit - List hashmap names in range (name_start, name_end].
    • hrlist name_start name_end limit - List hashmap names in range (name_start, name_end].
    • hkeys name key_start key_end - List keys of a hashmap in range (key_start, key_end].
    • hgetall name - Returns the whole hash, as an array of strings indexed by strings.
    • hscan name key_start key_end limit - List key-value pairs of a hashmap with keys in range (key_start, key_end].
    • hrscan name key_start key_end limit - List key-value pairs with keys in range (key_start, key_end], in reverse order.
    • hclear name - Delete all keys in a hashmap.
    • multi_hset name key1 value1 key2 value2 ... - Set multiple key-value pairs(kvs) of a hashmap in one method call.
    • multi_hget name key1 key2 ... - Get the values related to the specified multiple keys of a hashmap.
    • multi_hdel name key1 key2 ... - Delete specified multiple keys in a hashmap.
  • Sorted Set
    • zset name key score - Set the score of the key of a zset.
    • zget name key - Get the score related to the specified key of a zset
    • zdel name key - Delete specified key of a zset.
    • zincr name key num - Increment the number stored at key in a zset by num.
    • zexists name key - Verify if the specified key exists in a zset.
    • zsize name - Return the number of pairs of a zset.
    • zlist name_start name_end limit - List zset names in range (name_start, name_end].
    • zrlist name_start name_end limit - List zset names in range (name_start, name_end], in reverse order.
    • zkeys name key_start score_start score_end limit - List keys in a zset.
    • zscan name key_start score_start score_end limit - List key-score pairs where key-score in range (key_start+score_start, score_end].
    • zrscan name key_start score_start score_end limit - List key-score pairs of a zset, in reverse order. See method zkeys().
    • zrank name key - Returns the rank(index) of a given key in the specified sorted set.
    • zrrank name key - Returns the rank(index) of a given key in the specified sorted set, in reverse order.
    • zrange name offset limit - Returns a range of key-score pairs by index range [offset, offset + limit).
    • zrrange name offset limit - Returns a range of key-score pairs by index range [offset, offset + limit), in reverse order.
    • zclear name - Delete all keys in a zset.
    • zcount name score_start score_end - Returns the number of elements of the sorted set stored at the specified key which have scores in the range [score_start,score_end].
    • zsum name score_start score_end - Returns the sum of elements of the sorted set stored at the specified key which have scores in the range [score_start,score_end].
    • zavg name score_start score_end - Returns the average of elements of the sorted set stored at the specified key which have scores in the range [score_start,score_end].
    • zremrangebyrank name start end - Delete the elements of the zset which have rank in the range [start,end].
    • zremrangebyscore name start end - Delete the elements of the zset which have score in the range [start,end].
    • zpop_front name limit - Delete limit elements from front of the zset.
    • zpop_back name limit - Delete limit elements from back of the zset.
    • multi_zset name key1 score1 key2 score2 ... - Set multiple key-score pairs(kvs) of a zset in one method call.
    • multi_zget name key1 key2 ... - Get the values related to the specified multiple keys of a zset.
    • multi_zdel name key1 key2 ... - Delete specified multiple keys of a zset.
  • List
    • qpush_front name item1 item2 ... - Adds one or more than one element to the head of the queue.
    • qpush_back name item1 item2 ... - Adds an or more than one element to the end of the queue.
    • qpop_front name size - Pop out one or more elements from the head of a queue.
    • qpop_back name size - Pop out one or more elements from the tail of a queue.
    • qpush name item1 item2 ... - Alias of qpush_back.
    • qpop name size - Alias of qpop_front.
    • qfront name - Returns the first element of a queue.
    • qback name - Returns the last element of a queue.
    • qsize name - Returns the number of items in the queue.
    • qclear name - Clear the queue.
    • qget name index - Returns the element a the specified index(position).
    • qset name index val - Description
    • qrange name offset limit - Returns a portion of elements from the queue at the specified range [offset, offset + limit].
    • qslice name begin end - Returns a portion of elements from the queue at the specified range [begin, end].
    • qtrim_front name size - Remove multi elements from the head of a queue.
    • qtrim_back name size - Remove multi elements from the tail of a queue.
    • qlist name_start name_end limit - List list/queue names in range (name_start, name_end].
    • qrlist name_start name_end limit - List list/queue names in range (name_start, name_end], in reverse order.

License

Pouch is licensed under the MIT License. See LICENSE for the full license text.