SSDB PHP program api documentation


Help improve this document

SSDB PHP Client API Documentation

@Author: ideawu
@Update: 2014-11-05

SSDB is a high-performance NoSQL database that supports zset data structure and is used to replace Redis. The official website is http://ssdb.io. This document introduces the PHP client API of SSDB.

Note: The nouns "hashmap", "hash" and "map" used by SSDB have the same meaning. .

ClassSimpleSSDB

Quick Start

<?php
include_once('SSDB.php');
try{
    $ssdb = new SimpleSSDB('127.0.0.1', 8888);
}catch(SSDBException $e){
    die(LINE . ' ' . $e->getMessage());
}
$ret = $ssdb->set('key', 'value');
if($ret === false){
    // error!
}
echo $ssdb->get('key');

Error handling

If it cannot connect to the SSDB server, SimpleSSDB will throw an exception. Most methods (with a few exceptions) indicate an error by returning false. So Use forced equality (===) to determine the return value.

If a network error occurs, all methods will throw SSDBException.

Note: Due to implementation reasons, please ensure that the total size of all parameters does not exceed 10MB.

Method

SimpleSSDB::__construct

Description

Create an instance of SimpleSSDB, and connect to the SSDB server. If unable to connect to the server, an exception will be thrown.

Parameters

host - SSDB server Host name or IP.
port - The port number of the SSDB server.
timeout_ms - Optional, connection timeout, and sending and receiving data The timeout period, in milliseconds. The default is 2000 ms.

Return value

Instance of SimpleSSDB.

Example

$ssdb = new SimpleSSDB('127.0.0.1', 8888);

auth

Since: 1.7.0.0

Description

Configure the password, which will be used to verify with the server later. This verification is not performed immediately, but is sent to the server when you execute the first command. Note that the password is transmitted in clear text!

Parameters

password -

Return value

If an error occurs, it returns false, otherwise it returns null.

Example

$ssdb->auth('very-strong-password');

set

Description

Set the value content of the specified key.

Parameters

key -
value -

Return value

Return on error false, other values ​​indicate normal.

Example

$ssdb->set('key', 'value');

setx

Description

Set the value content of the specified key and set the survival time.

Parameters

key -
value -
ttl - Survival time (seconds)

Return value

If an error occurs, false will be returned, other values ​​​​mean normal.

Example

$ssdb->setx('key', 'value', 60);

setnx

Description

When the key does not exist, set the value content of the specified key. If it already exists, it will not be set.

Parameters

key -
value -

Return value

If an error occurs, false will be returned. 1: value has been set, 0: key already exists and will not be updated.

Example

$ssdb->setnx('key', 'value');

expire

Description

Set the survival time of key (only for KV type).

Parameters

key -
ttl - Survival time (seconds)

Return value

If an error occurs, false is returned. If the key exists and is set successfully, 1 is returned. If the key does not exist, 0 is returned.

Example

$ssdb->expire('key', 60);

ttl

Description

Returns the survival time of key (only for KV type).

Parameters

key -

Return value

If an error occurs, false will be returned. Otherwise, the survival time of the key (seconds) will be returned. -1 means that the survival time is not set.

Example

$ssdb->ttl('key');

get

Description

Get the specified key Value content.

Parameters

key -

Return value

If the key does not exist, return null, if an error occurs, return false, otherwise return the value corresponding to the key.

Example

$ssdb->get('key');

getset

Description

Update the value corresponding to the key and return the old value before the update .

Parameter

key -
value -

Return value

If the key does not exist, return null, if an error occurs, return false, otherwise return the value corresponding to the key Content.

Example

$ssdb->getset('key', 'value');
##del

Description

Delete the specified key.

Parameters

key -

Return value

If an error occurs, false is returned, and other values ​​indicate normal. You cannot use the return value to determine whether the deleted key exists.

Example

$ssdb->del('key');

incr

From 1.7.0.1, if value cannot be converted to an integer, incr will return an error.

Instructions

Increase the value corresponding to key by num. The parameter num can be a negative number . If the original value is not an integer (integer in string form), it will be converted to an integer first.

Parameters

key -
num - Optional, must be a signed integer, the default is 1.

Return value

If an error occurs, return false, otherwise return the new value.

Examples

$ssdb->incr('key', 1);
##exists

Description

Judgment Whether the specified key exists.

Parameters

key -

Return value

If exists, return

true, otherwise return false.

Example
$ssdb->exists('key');

getbit

Description

Get the bit value (BIT) at the specified position in the string.

Parameters

key -
offset - Bit offset

Return value

Returns the bit value (0 or 1). If the key does not exist or the offset exceeds the live string length range, 0 is returned.

Example

$ssdb->getbit('key', 9);

setbit

Description

Setting The bit value (BIT) at the specified position in the string, the length of the string will be automatically extended.

Parameters

key -
offset - Bit offset, value range [0, 1073741824]
val - 0 or 1

Return value

Return the original bit value. If val is not 0 or 1, return false.

Example

$ssdb->setbit('key', 9, 1);

bitcount

Description

Calculate the number of bits contained in a substring of a string The number of values ​​​​is 1. If start is a negative number, it is counted from the end of the string. If end is a negative number, it is counted from the end of the string (inclusive). Similar Redis bitcount

Parameters

key -
start - Optional, byte offset of the substring Shift
end - Optional

Return value

Return the number of bits whose value is 1. Error Return false.

Example

$ssdb->bitcount('key', 2, 10);

countbit

Description

Calculate the number of bit values ​​1 contained in the substring of the string. If start is a negative number, count from the end of the string. If size is a negative number, which means that many bytes are ignored from the end of the string.

Parameters

key -
start - Optional, the byte offset of the substring
size - Optional, the length of the substring ( Number of bytes), the default is to the last byte of the string

Return value

Returns the number of bits with a bit value of 1. Returns on error false.

Example

$ssdb->countbit('key', 2, 10);

substr

#Description

Get A substring of a string. If start is a negative number, it starts from the end of the string. If size is a negative number, it means it starts from the end of the string and ignores that many characters. Section (similar to PHP’s substr()).

Parameters

key -
start - optional, int, byte offset of the substring
size - optional, int, length of the substring (number of bytes) , the default is to the last byte of the string

Return value

The substring of the string.

Example

$ssdb->substr('key', 2, 10);

strlen

Description

Calculate the length of the string (number of bytes ).

Parameters

key -

Return value

Returns the length of the string. If key does not exist, 0 is returned.

Example

$ssdb->strlen('key');

keys/rkeys

Description

List the key list in the interval (key_start, key_end].

("", ""] represents the entire interval.

Parameters

key_start - Returned starting key (not included), empty string means -inf.
key_end - The returned end key (inclusive), the empty string represents inf.
limit - The maximum number of elements returned.

Return value

If an error occurs, return false, otherwise return an array containing the key.

Example

$ssdb->keys('a', 'z', 10);

scan

Description

Column Key-value list from the interval (key_start, key_end].

("", ""] represents the entire interval.

Parameters

key_start - The returned starting key (not included), an empty string indicates -inf.
key_end - The returned end key (included), An empty string represents inf.
limit - This many elements can be returned at most.

Return value

If an error occurs, return false, otherwise return a number association group containing key-value.

Example

$ssdb->scan('a', 'z', 10);
Traverse the key-value pair list
$start = ''; 
$limit = 1000;
while(1){
    $kvs = $ssdb->scan($start, '', $limit);
    if(!$kvs){
        break;
    }
    // do something on key-value pairs...
    $keys = array_keys(array_slice($kvs, -1, 1, true));
    $max_key = $keys[0];
    $start = $max_key;
}

rscan

Description

List is in the interval (key_start , key_end] key-value list, in reverse order.

("", ""] represents the entire interval.

Parameters

key_start - The returned starting key (not included), the empty string represents inf.
key_end - Returned end key (inclusive), empty string means -inf.
limit - Return at most this many elements.

Return value

If an error occurs, return false, otherwise return a number association group containing key-value.

Example

$ssdb->rscan('a', 'z', 10);

multi_set

Description

Set a batch of key-values ​​in batches.

Parameters

##kvs - Associative array containing key-value.

Return The value

returns

false if there is an error, other values ​​indicate normal.

Example
$ssdb->multi_set(array(
    'a' => 1,
    'b' => 2,
));

multi_get

Description

Get the value content corresponding to a batch of keys in batches.

Parameters

keys - Array containing key.

Return value

If an error occurs, it returns false, otherwise it returns an associative array containing key-value. If a key does not exist, it will not appear in the return array.

Example

$ssdb->multi_get(array('k1', 'k2'));

multi_del

Description

Delete a batch in batches key and its corresponding value content.

Parameters

keys - Array containing key.

Return value

If an error occurs, false will be returned. Other values ​​indicate normal.

Example

$ssdb->multi_del(array('k1', 'k2'));

hset

Description

Set the value content corresponding to the specified key in the hashmap.

Parameters

name - The name of the hashmap.
key - The key in the hashmap.
value - The value content corresponding to key.

Return value

If an error occurs, false will be returned , other values ​​indicate normal.

Example

$ssdb->hset('h', 'key', 'value');

hget

Description

Get the value content of the specified key in the hashmap.

Parameters

name - The name of the hashmap.
key - the key in the hashmap.

Return value

If the key does not exist Then return null, if an error occurs, return false, otherwise return the value corresponding to the key.

Example

$ssdb->hget('h', 'key');
##hdel

Description

Get The specified key in the hashmap.

Parameters

name - The name of the hashmap.
key - key in hashmap.

Return value

If an error occurs, it returns

false, other values ​​​​mean normal. You It is impossible to judge whether the deleted key exists through the return value.

Example
$ssdb->hdel('h', 'key');

hincr

From 1.7.0.1, if value cannot be converted to an integer, incr will return an error.

Instructions

Enable # in hashmap ##key

The corresponding value is increased by num. The parameter num can be a negative number. If the original value is not an integer (an integer in string form), it will be converted to Integer.

Parameters

name - The name of the hashmap.
key -
num - Optional, must be a signed integer, the default is 1.

Return value

Returns if an error occurs false, otherwise return the new value.

Example

$ssdb->hincr('h', 'key', 1);

hexists

Description

Determine whether the specified key exists in the hashmap.

Parameters

name - The name of the hashmap.
key -

Return value

If it exists, return true, otherwise return false.

Example

$ssdb->hexists('h', 'key');

hsize

Description

Returns the number of elements in the hashmap.

Parameters

name - The name of the hashmap.

Return value

If an error occurs, false is returned, otherwise the number of elements is returned, 0 means there is no hashmap (empty).

Example

$ssdb->hsize('h');

hlist, hrlist

Description

List the hashmap whose names are in the interval (name_start, name_end].

("", ""] represents the entire interval.

Parameters

##name_start - The starting name returned (not included), the empty string represents -inf.
name_end - the returned end name (not included), the empty string represents inf.
limit - Returns at most this many elements.

Return value

If an error occurs,

false will be returned. Return the name containing the Array.

Example

$ssdb->hlist('a', 'z', 10);
##hkeys

Description

Column Output the key list in the hashmap in the interval (key_start, key_end].

("", ""] represents the entire interval.

Parameters

name - The name of the hashmap.
key_start - The starting key (not included), an empty string means -inf.
key_end - End key (inclusive), empty string represents inf.
limit - Return at most this many elements.

Return value

If an error occurs, return

false, otherwise return an array containing the key.

Example
$ssdb->hkeys('h', 'a', 'z', 10);

hgetall

Description

Return the entire hashmap.

Parameters

name - The name of the hashmap.

Return value

If an error occurs, return false, otherwise return an associative array containing key-value.

Example

$ssdb->hgetall('h');

hscan

Description

List the key-value list in the interval (key_start, key_end] in the hashmap.

("", ""] represents the entire range.

Parameters

name - The name of the hashmap.
key_start - Returned starting key (not included), empty string means -inf.
key_end - Returned end key (included), empty String representation inf.
limit - Return at most this many elements.

Return value

If If an error occurs, false is returned, otherwise an associative array containing key-value is returned.

Example

$ssdb->hscan('h', 'a', 'z', 10);

Traverse hash:

$start = '';
while(1){
    $kvs = $ssdb->hscan($name, $start, '', 10);
    if(!$kvs){
        break;
    }
    // do sth on kvs here
$keys = array_keys($kvs);
$start = $keys[count($keys) - 1];

}

hrscan

Description

List the hashmap in the interval (key_start, key_end] key-value list, reverse order.

("", ""] represents the entire interval.

Parameters

name - The name of the hashmap.
key_start - The returned starting key (not included), the empty string represents inf.
key_end - Returned end key (inclusive), empty string means -inf.
limit - Return at most this many elements.

Return value

If an error occurs, return false, otherwise return an associative array containing key-score.

Example

$ssdb->hrscan('h', 'a', 'z', 10);

hclear

Description

Delete all keys in the hashmap.

Parameters

name - The name of the hashmap.

Return value

If an error occurs, return false, otherwise return the number of deleted keys.

Example

$ssdb->hclear('h');

multi_hset

Description

Batch set the key-value in hashmap.

Parameters

name - The name of the hashmap.
kvs - Associative array containing key-value.

Return value

If an error occurs, false will be returned. Other values ​​indicate normal.

Example

$ssdb->multi_hset('h', array(
    'a' => 1,
    'b' => 2,
));

multi_hget

Description

Get the weight values ​​corresponding to multiple keys in the hashmap in batches.

Parameters

name - The name of the hashmap.
keys - An array containing keys.

Return value

If an error occurs, return false, otherwise return an associative array containing key-value. If a key does not exists, it will not appear in the return array.

Example

$ssdb->multi_hget('h', array('k1', 'k2'));

multi_hdel

Instructions

Delete keys in hashmap in batches.

Parameters

name - The name of the hashmap.
keys - The array containing the key.

Return value

Return on error false, other values ​​indicate normal.

Example

$ssdb->multi_hdel('h', array('k1', 'k2'));

zset

Description

Set the weight value corresponding to the specified key in zset.

Parameters

name - The name of zset.
key - The key in zset.
score - Integer, the weight value corresponding to the key

Return value

If an error occurs, it will be returned false, other values ​​indicate normal.

Example

$ssdb->zset('z', 'key', 100);

zget

Description

Get the weight value of the specified key in zset.

Parameters

name - The name of the zset.
key - The key in the zset.

Return value

If the key is not If it exists, it returns null, if there is an error, it returns false, otherwise it returns the weight value corresponding to the key.

Example

$ssdb->zget('z', 'key');
##zdel

Description

Get The specified key in zset.

Parameters

name - The name of zset.
key - key.

Return value

If an error occurs, it will return

false, other values ​​​​mean normal. You It is impossible to judge whether the deleted key exists through the return value.

Example
$ssdb->zdel('hz, 'key');

zincr

Description

Increase the value corresponding to

key in zset by num. The parameter num can be a negative number. If the original value is not an integer (integer in string form), it will be converted to an integer first.

Parameters

name - The name of zset.
key -
num - must be a signed integer.

Return value

If an error occurs, false will be returned. Otherwise return the new value.

Example

$ssdb->zincr('z', 'key', 1);
##zexists

Description

Determine whether the specified key exists in zset.

Parameters

name - zset Name.
key -

Return value

If exists, return

true , otherwise return false.

Example
$ssdb->zexists('z', 'key');

##zsize

Description

Returns the number of elements in zset.

Parameters

name - The name of zset.

Return value

If an error occurs, false is returned, otherwise the number of elements is returned, 0 means there is no zset (empty).

Example

$ssdb->zsize('z');

zlist, zrlist

Description

List the zset.## whose names are in the interval (name_start, name_end]

#("", ""] represents the entire interval.

Parameters

##name_start
- The starting name returned (not included), the empty string represents -inf.
name_end
- the returned end name (not included), the empty string represents inf.
limit
- Return at most this many elements.
Return value

If an error occurs,

false

will be returned, otherwise it will return the name containing the name Array.

Example

$ssdb->zlist('a', 'z', 10);

zkeys

Description

Column Get the key list in zset. See zscan().

parameter

name - The name of the zset.
key_start - See zscan().
score_start - See zscan().
score_end - See zscan() .
limit - Return at most this many elements.

Return value

Return if an error occurs false, otherwise return the array containing key.

Example

$ssdb->zkeys('z', '', 1, 100, 10);
##zscan

Description

Column Extract the key-score list in the zset that is in the interval (key_start score_start, score_end]. If key_start is empty, then the keys whose corresponding weight value is greater than or equal to score_start will be returned. If key_start is not empty, then the corresponding keys whose weight value is greater than score_start will be returned. , or a key that is greater than key_start and has a corresponding weight value equal to score_start will be returned.

In other words, the returned key is in

(key.score == score_start && key > key_start || key.score > score_start), and key.score <= score_end interval. First judge score_start, score_end, and then judge key_start.

("", ""] represents the entire interval .

Parameters

name - the name of zset.
key_start - score_start Corresponding key.
score_start - Returns the minimum weight value of the key (may not be included, depends on key_start), an empty string means -inf.
score_end - Returns the maximum weight value of key (inclusive), an empty string indicates inf.
limit - Returns at most this many elements.

Return value

If an error occurs, return

false, otherwise return an associative array containing key-score.

Example
$ssdb->zscan('z', '', 1, 100, 10);

Traverse zset:

$key_start = ''; 
$score_start = ''; 
while(1){
    $items = $ssdb->zscan($zname, $key_start, $score_start, '', 10);
    if(!$items){
        break;
    }
    foreach($items as $key=>$score){
        // process($key, $score)...
    // 记住最大的元素和它的权重
    $key_start = $key;
    $score_start = $score;
}   

}

zrscan

Description

List the key-score list in zset, reverse Sequence. See zkeys().

parameters

##name - zset Name.
key_start - See zkeys().
score_start - See zkeys().
score_end - See zkeys().
limit - Return at most this many elements.

Return value

If an error occurs, return

false, otherwise return an associative array containing key-score.

Example
$ssdb->zrscan('z', '', 100, 1, 10);

##zrank, zrrank

Instructions

Attention! This method may be very slow! Please use it in an offline environment.

Returns the sorting position (ranking) of the specified key in zset, ranking starts from 0. zrrank gets the reverse order ranking.

Parameters

name - The name of zset.
key -

Return value

found .

##If an error occurs, it will return

false, null means that the key does not exist in zset, otherwise the ranking will be returned.

Example
$ssdb->zrank('z', 'k1');

zrange, zrrange

Instructions

Note ! This method will become slower when the offset gets larger and larger!

Get the key-score pair according to the subscript index interval [offset, offset limit), the subscript starts from 0. zrrange is the reverse Get in order.

Parameters

name - the name of zset.
offset - a positive integer, from now on Start returning at the index. Start from 0.
limit - Positive integer, return at most this many key-score pairs.

Return value

If an error occurs, return false, otherwise return an associative array containing key-score.

Example

$ssdb->zrange('z', 0, 10);

zclear

Description

Delete all keys in zset.

Parameters

name - The name of zset.

Return value

If an error occurs Return false, otherwise return the number of deleted keys.

Example

$ssdb->zclear('z');

zcount

Description

Returns the number of keys in the interval [start,end].

Parameters

name - The name of the zset.
score_start - The minimum weight value of the key (Inclusive), the empty string represents -inf.
score_end - the maximum weight value of key (Inclusive), the empty string represents inf.

Return value

If an error occurs, return false, otherwise return the number of keys that meet the conditions.

Example

$ssdb->zcount('z', 0, 100);

zsum

Description

Returns the sum of the scores of the key in the interval [start,end].

Parameters

name - the name of zset.
score_start - the key The minimum weight value (inclusive), the empty string represents -inf.
score_end - the maximum weight value of the key (inclusive), the empty string represents inf.

Return value

If an error occurs, return false, otherwise return the sum of the scores that meet the conditions.

Example

$ssdb->zsum('z', 0, 100);
##zavg

Description

Return The key is the average value of the scores in the interval [start, end].

Parameters

name - The name of the zset.
score_start - The minimum weight value of key (inclusive), an empty string indicates -inf.
score_end - The maximum weight value of key (inclusive) , the empty string represents inf.

Return value

If an error occurs,

false is returned, otherwise the average score that meets the conditions is returned Value.

Example
$ssdb->zavg('z', 0, 100);

zremrangebyrank

Description

Delete elements whose position is in the interval [start,end].

Parameters

name - The name of zset.
start - (Inclusive).
end -(Inclusive).

Return value

If an error occurs, false will be returned , otherwise return the number of deleted elements.

Example

$ssdb->zremrangebyrank('z', 1, 2);

zremrangebyscore

Description

Delete elements whose weight is in the interval [start,end].

Parameters

name - The name of the zset.
start - (Inclusive).
end -(Inclusive).

Return value

If an error occurs, false is returned, otherwise the number of deleted elements is returned.

Example

$ssdb->zremrangebyscore('z', 1, 2);

zpop_front

Description

From The zset header deletes and returns limit elements.

Parameters

name - The name of the zset.
limit - A positive integer, the maximum number of key-score pairs to be deleted and returned.

Return value

If an error occurs, return false, otherwise return an associative array containing key-score.

Example

$ssdb->zpop_front('z', 3);

zpop_back

Description

Delete and return limit elements from the end of zset.

Parameters

name - the name of zset.
limit - a positive integer, at most Delete and return so many key-score pairs.

Return value

If an error occurs, false is returned, otherwise the key is returned Associative array of -score.

Example

$ssdb->zpop_back('z', 3);

multi_zset

Description

Batch set key-score in zset.

Parameters

name - the name of zset .
kvs - Associative array containing key-score.

Return value

If an error occurs, # will be returned ##false, other values ​​indicate normal.

Example
$ssdb->multi_zset('z', array(
    'a' => 1,
    'b' => 2,
));

multi_zget

Instructions

Get the weight values ​​corresponding to multiple keys in zset in batches.

Parameters

name - The name of zset.
keys - An array containing keys.

Return value

If an error occurs, return false, otherwise return an associative array containing key-score. If a key does not exists, it will not appear in the return array.

Example

$ssdb->multi_zget('z', array('k1', 'k2'));

multi_zdel

Instructions

Delete keys in zset in batches.

Parameters

name - The name of zset.
keys - The array containing key.

Return value

Return in case of error false, other values ​​indicate normal.

Example

$ssdb->multi_zdel('z', array('k1', 'k2'));

qsize

Description

Returns the length of the queue.

Parameters

name -

Return value

Return false on error, otherwise return an integer, 0 means the queue does not exist (or is empty).

Example

$ssdb->qsize('q');

qlist, qrlist

Description

List the queue/list whose names are in the interval (name_start, name_end].

("", ""] represents the entire interval.

Parameters

name_start - The returned starting name (not included ), the empty string represents -inf.
name_end - the returned end name (inclusive), the empty string represents inf.
limit - Return at most this many elements.

Return value

If an error occurs, false is returned, and an array containing the name is returned.

Example

$ssdb->qlist('a', 'z', 10);

qclear

Description

Clear A queue.

Parameters

name -

Return value

Error return false.

Example

$ssdb->qclear('q');
##qfront

Description

Returns the first element of the queue.

Parameters

name -

Return value

If an error occurs,

false will be returned. If the queue does not exist (or is empty), # will be returned. ##null, otherwise return an element.

Example

$ssdb->qfront('q');

qback

Description

Return The last element of the queue.

Parameters

name -

Return value

If an error occurs, false is returned. If the queue does not exist (or is empty), null is returned. Otherwise, an element is returned.

Example

$ssdb->qback('q');

qget

Description

Returns the element at the specified position. 0 means the first element, 1 is the second... -1 is the last.

Parameters

name -
index - Negative numbers can be passed.

Return value

Error return false, If an element does not exist at the specified position, return null, otherwise return an element.

Example

$ssdb->qget('q', -2);

qset

Since: 1.7.0.0

Description

Update the element located at index position. If it exceeds the existing element range, an error will be returned.

Parameters

name -
index - Can pass negative numbers.
val -

Return value

If an error occurs, false will be returned. Other values ​​indicate normal.

Example

$ssdb->qset('q', 0, 'new val');

qrange

Description

Returns the element whose subscript is in the area [offset, offset limit].

Parameters

name - The name of the queue.
offset - Integer, from here on out Start returning from 0. It can be a negative number, which means counting from the end.
limit - a positive integer, up to this many elements can be returned.

Return value

If an error occurs, return false, otherwise return an array.

Example

$ssdb->qrange('q', 0, 10);

qslice

Description

Returns the element whose subscript is in the area [begin, end]. begin and end can Is a negative number

Parameter

name -
begin -
end -

Return value

If an error occurs, false is returned, otherwise an array containing the elements is returned.

Example

$ssdb->qslice('q', 0, -1);
##qpush

Description

this The function is an alias of

qpush_back().

##qpush_front

Description

Add one or more elements to the head of the queue

Parameters

##name
-
item
- String or string array.
Return value

After adding elements, the length of the queue, returned in case of error false

.

Example

$ssdb->qpush_front('q', 'a');

##qpush_backDescription

Add one or more elements to the end of the queue

Parameters

name -
item - String or string array.

Return value

After adding elements, the length of the queue, error return false.

Example

$ssdb->qpush_back('q', 'a');

qpop

Description

This function is qpop_front( ) alias.

qpop_front

Description

Pop one from the head of the queue Or multiple elements.

Parameters

name -
size - Optional, up to this many can be popped from the queue Elements

Return value

Error returns false. When size is not specified or is less than or equal to 1 , if the queue does not exist (or is empty), return null, otherwise delete and return an element. When size is greater than or equal to 2, return an array containing the popped element.

Example

$ssdb->qpop_front('q');

qpop_back

Instructions

From Pop one or more elements from the end of the queue.

Parameters

##name -
size - Optional, at most this many elements can be popped from the queue

Return value

Error returns

false. When ## When #size is not specified or is less than or equal to 1, if the queue does not exist (or is empty), null will be returned, otherwise an element will be deleted and returned. When size is greater than or equal to 2 , returns an array containing the popped elements.

Example

$ssdb->qpop_back('q');

qtrim_front

Instructions

From Delete multiple elements from the head of the queue.

Parameters

name -
size - Delete at most this many elements from the queue

Return value

Return on error false. Returns the number of deleted elements.

Example

$ssdb->qtrim_front('q', 3);

qtrim_back

Description

Delete multiple elements from the head of the queue.

Parameters

name -
size - The maximum number of elements to be deleted from the queue

Return value

Error return false. Return the deleted Number of elements.

Example

$ssdb->qtrim_back('q', 3);

batch, exec

Description

Execute a batch of commands in batches. Batch commands can reduce the interaction delay between the client and the server, and improve performance and response speed.

This feature is implemented on the client, ssdb-server Batch commands are not supported, but are executed one by one as independent commands. The size of all commands and parameters should be less than 10MB.

Parameters

Return value

If exec() makes an error, it returns false, otherwise it returns one The array contains the results corresponding to each command.

Example

$ret = $ssdb->batch()
    ->set('a', 1)
    ->get('a')
    ->exec();
// 或者
$ssdb->batch();
$ssdb->set('a', 1);
$ssdb->get('a');
$ret = $ssdb->exec();

dbsize

Description

Returns the estimated size of the database, in bytes. If the server has compression enabled, returns the compressed size.

Parameters

Return value

Error return false. Returns the database size.

Example

$ssdb->dbsize();

info

Description

Return server information.

Parameters

opt - Optional, can be cmd, leveldb

Return value

Error return false. Returns an associative array of server information.

Example

$ssdb->info();