This extension allows Vedis.
Documentation for Vedis can be found at » http://vedis.symisc.net/.
% phpize
% ./configure
% make
% make test
% make install
vedis.ini:
extension=vedis.so
$vedis = new Vedis;
$vedis->set('key', 'value');
$value = $vedis->get('key');
- get - Get the value of a key
- set - Set the string value of a key
- setnx - Set the value of a key, only if the key does not exist
- incr, incrBy - Increment the value of a key
- decr, decrBy - Decrement the value of a key
- mGet - Get the values of all the given keys
- mSet, mSetNX - Set multiple keys to multiple values
- getSet - Set the string value of a key and return its old value
- append - Append a value to a key
- strlen - Get the length of the value stored in a key
- del, delete - Delete a key
- exists - Determine if a key exists
- rename - Rename a key
Description: Get the value related to the specified key
key
String or NULL: If key didn't exist, NULL
is returned. Otherwise,
the value related to this key is returned.
$vedis->get('key');
Description: Set the string value in argument as value of the key.
key value
Bool TRUE
if the command is successful.
$vedis->set('key', 'value');
Description: Set the string value in argument as value of the key if the key doesn't already exist in the database.
key value
Bool TRUE
in case of success, FALSE
in case of failure.
$vedis->setnx('key', 'value'); /* TRUE */
$vedis->setnx('key', 'value'); /* FALSE */
Description: Remove specified keys.
keys: key1, key2, ... , keyN: Any number of parameters, each a key.
Long Number of keys deleted.
$vedis->set('key1', 'val1');
$vedis->set('key2', 'val2');
$vedis->set('key3', 'val3');
$vedis->set('key4', 'val4');
$vedis->delete('key1', 'key2'); /* return 2 */
$vedis->delete('key4', 'key10'); /* return 1 */
Description: Verify if the specified key exists.
key
BOOL: If the key exists, return TRUE
, otherwise return FALSE
.
$vedis->set('key', 'value');
$vedis->exists('key'); /* TRUE */
$vedis->exists('NonExistingKey'); /* FALSE */
Description: Increment the number stored at key by one. If the second argument is filled, it will be used as the integer value of the increment.
key value: value that will be added to key (only for incrBy)
INT the new value
$vedis->incr('key1'); /* key1 didn't exists, set to 0 before the increment */
/* and now has the value 1 */
$vedis->incr('key1'); /* 2 */
$vedis->incr('key1'); /* 3 */
$vedis->incr('key1'); /* 4 */
$vedis->incrBy('key1', 10); /* 14 */
Description: Decrement the number stored at key by one. If the second argument is filled, it will be used as the integer value of the decrement.
key value: value that will be substracted to key (only for decrBy)
INT the new value
$vedis->decr('key1'); /* key1 didn't exists, set to 0 before the increment */
/* and now has the value -1 */
$vedis->decr('key1'); /* -2 */
$vedis->decr('key1'); /* -3 */
$vedis->decrBy('key1', 10); /* -13 */
Description: Get the values of all the specified keys. If one or more keys
dont exist, the array will contain NULL
at the position of the key.
Array: Array containing the list of the keys
Array: Array containing the values related to keys in argument
$vedis->set('key1', 'value1');
$vedis->set('key2', 'value2');
$vedis->set('key3', 'value3');
$vedis->mGet(array('key1', 'key2', 'key3')); /* array('value1', 'value2', 'value3'); */
$vedis->mGet(array('key0', 'key1', 'key5')); /* array(NULL, 'value2', NULL); */
Description: Sets multiple key-value pairs in one atomic command. MSETNX only returns TRUE if all the keys were set (see SETNX).
Pairs: array(key => value, ...)
Bool TRUE
in case of success, FALSE
in case of failure.
$vedis->mset(array('key0' => 'value0', 'key1' => 'value1')); /* TRUE */
$vedis->msetnx(array('key0' => 'value10', 'key1' => 'value11')); /* FALSE */
var_dump($vedis->get('key0'));
var_dump($vedis->get('key1'));
Output:
string(6) "value0"
string(6) "value1"
Description: Sets a value and returns the previous entry at that key.
key: key
STRING: value
A string, the previous value located at this key.
$vedis->set('x', '42');
$vedis->getSet('x', 'lol'); /* 42, replaces x by 'lol' */
$vedis->get('x'); /* lol */
Description: Renames a key.
STRING: srckey, the key to rename.
STRING: dstkey, the new name for the key.
BOOL: TRUE
in case of success, FALSE
in case of failure.
$vedis->set('x', '42');
$vedis->rename('x', 'y');
$vedis->get('y'); /* 42 */
$vedis->get('x'); /* NULL */
Description: Append specified string to the string stored in specified key.
key value
INTEGER: Size of the value after the append
$vedis->set('key', 'value1');
$vedis->append('key', 'value2'); /* 12 */
$vedis->get('key'); /* value1value2 */
Description: Get the length of a string value.
key
INTEGER
$vedis->set('key', 'value');
$vedis->strlen('key'); /* 5 */
- hSet - Set the string value of a hash field
- hSetNx - Set the value of a hash field, only if the field does not exist
- hGet - Get the value of a hash field
- hLen - Get the number of fields in a hash
- hDel - Delete one or more hash fields
- hKeys - Get all the fields in a hash
- hVals - Get all the values in a hash
- hGetAll - Get all the fields and values in a hash
- hExists - Determine if a hash field exists
- hMSet - Set multiple hash fields to multiple values
- hMGet - Get the values of all the given hash fields
Description: Adds a value to the hash stored at key. If this value is
already in the hash, FALSE
is returned.
key field value
BOOL TRUE
if the field was set, FALSE
if it was already present.
$vedis->hSet('h', 'key1', 'hello'); /* 'key1' => 'hello' in the hash at "h" */
$vedis->hGet('h', 'key1'); /* hello */
$vedis->hSet('h', 'key1', 'plop'); /* value was replaced. */
$vedis->hGet('h', 'key1'); /* returns "plop" */
Description: Adds a value to the hash stored at key only if this field isn't already in the hash.
BOOL TRUE
if the field was set, FALSE
if it was already present.
$vedis->hSetNx('h', 'key1', 'hello'); /* TRUE, 'key1' => 'hello' in the hash at "h" */
$vedis->hSetNx('h', 'key1', 'world'); /* FALSE, 'key1' => 'hello' in the hash at "h". No change since the field wasn't replaced. */
Description: Gets a value from the hash stored at key. If the hash table
doesn't exist, or the key doesn't exist, FALSE
is returned.
key field
STRING The value, if the command executed successfully
BOOL FALSE
in case of failure
$vedis->hGet('h', 'key');
Description: Returns the length of a hash, in number of items
key
LONG the number of items in a hash, FALSE
if the key doesn't exist or isn't
a hash.
$vedis->hSet('h', 'key1', 'hello');
$vedis->hSet('h', 'key2', 'plop');
$vedis->hLen('h'); /* 2 */
Description: Removes a value from the hash stored at key. If the hash
table doesn't exist, or the key doesn't exist, FALSE
is returned.
key field
BOOL TRUE
in case of success, FALSE
in case of failure
$vedis->hset('h', 'key1', 'val1');
$vedis->hdel('h', 'key1');
Description: Returns the keys in a hash, as an array of strings.
Key: key
An array of elements, the keys of the hash. This works like PHP's array_keys().
$vedis->hSet('h', 'a', 'x');
$vedis->hSet('h', 'b', 'y');
$vedis->hSet('h', 'c', 'z');
$vedis->hSet('h', 'd', 't');
var_dump($vedis->hKeys('h'));
Output:
array(4) {
[0]=>
string(1) "a"
[1]=>
string(1) "b"
[2]=>
string(1) "c"
[3]=>
string(1) "d"
}
Description: Returns the values in a hash, as an array of strings.
Key: key
An array of elements, the values of the hash. This works like PHP's array_values().
$vedis->hSet('h', 'a', 'x');
$vedis->hSet('h', 'b', 'y');
$vedis->hSet('h', 'c', 'z');
$vedis->hSet('h', 'd', 't');
var_dump($vedis->hVals('h'));
Output:
array(4) {
[0]=>
string(1) "x"
[1]=>
string(1) "y"
[2]=>
string(1) "z"
[3]=>
string(1) "t"
}
Description: Returns the whole hash, as an array of strings indexed by strings.
Key: key
An array of elements, the contents of the hash.
$vedis->hSet('h', 'a', 'x');
$vedis->hSet('h', 'b', 'y');
$vedis->hSet('h', 'c', 'z');
$vedis->hSet('h', 'd', 't');
var_dump($vedis->hGetAll('h'));
Output:
array(4) {
["a"]=>
string(1) "x"
["b"]=>
string(1) "y"
["c"]=>
string(1) "z"
["d"]=>
string(1) "t"
}
Description: Verify if the specified member exists in a key.
key field
BOOL: If the member exists in the hash table, return TRUE
, otherwise return
FALSE
.
$vedis->hSet('h', 'a', 'x');
$vedis->hExists('h', 'a'); /* TRUE */
$vedis->hExists('h', 'NonExistingKey'); /* FALSE */
Description: Fills in a whole hash. Non-string values are converted to
string, using the standard (string)
cast. NULL values are stored as empty
strings.
key members: key -> value array
BOOL
$vedis->hMset('user:1', array('name' => 'Joe', 'salary' => 2000));
Description: Retrieve the values associated to the specified fields in the hash.
key memberKeys Array
Array An array of elements, the values of the specified fields in the hash, with the hash keys as array keys.
$vedis->hSet('h', 'field1', 'value1');
$vedis->hSet('h', 'field2', 'value2');
$vedis->hmGet('h', array('field1', 'field2')); /* array('field1' => 'value1', 'field2' => 'value2') */
- lIndex, lGet - Get an element from a list by its index
- lPop - Remove and get the first element in a list
- lPush - Prepend one or multiple values to a list
- lLen, lSize - Get the length/size of a list
Description: Return the specified element of the list stored at the specified key.
0 the first element, 1 the second ... -1 the last element, -2 the penultimate ...
Return FALSE
in case of a bad index or a key that doesn't point to a list.
key index
String the element at this index
NULL if the key identifies a non-string data type, or no value corresponds to
this index in the list Key
.
$vedis->lPush('key1', 'A');
$vedis->lPush('key1', 'B');
$vedis->lPush('key1', 'C'); /* key1 => [ 'A', 'B', 'C' ] */
$vedis->lGet('key1', 0); /* A */
$vedis->lGet('key1', -1); /* C */
$vedis->lGet('key1', 10); /* NULL */
Description: Return and remove the first element of the list.
key
STRING if command executed successfully
BOOL FALSE
in case of failure (empty list)
$vedis->lPush('key1', 'A');
$vedis->lPush('key1', 'B');
$vedis->lPush('key1', 'C'); /* key1 => [ 'A', 'B', 'C' ] */
$vedis->lPop('key1'); /* key1 => [ NULL, 'B', 'C' ] */
Description: Adds the string value to the head (left) of the list. Creates
the list if the key didn't exist. If the key exists and is not a list, FALSE
is returned.
key value String, value to push in key
LONG The new length of the list in case of success, FALSE
in case of Failure.
$vedis->lPush('key1', 'C'); /* 1 */
$vedis->lPush('key1', 'B'); /* 2 */
$vedis->lPush('key1', 'A'); /* 3 */
/* key1 now points to the following list: [ 'A', 'B', 'C' ] */
Description: Returns the size of a list identified by Key.
If the list didn't exist or is empty, the command returns 0. If the data type
identified by Key is not a list, the command return FALSE
.
key
LONG The size of the list identified by Key exists.
BOOL FALSE
if the data type identified by Key is not list
$vedis->lPush('key1', 'A');
$vedis->lPush('key1', 'B');
$vedis->lPush('key1', 'C'); /* key1 => [ 'A', 'B', 'C' ] */
$vedis->lSize('key1');/* 3 */
$vedis->lPop('key1');
$vedis->lSize('key1');/* 2 */
- sAdd - Add one or more members to a set
- sCard, sSize - Get the number of members in a set
- sDiff - Subtract multiple sets
- sInter - Intersect multiple sets
- sIsMember - Determine if a given value is a member of a set
- sMembers - Get all the members in a set
- sPop - Remove and get the last element in a set
- sRem, sRemove - Remove one or more members from a set
- sPeek - Get the last element in a set
- sTop - Get the first element in a set
Description: Adds a value to the set value stored at key. If this value is
already in the set, FALSE
is returned.
key value
LONG the number of elements added to the set.
$vedis->sAdd('key1' , 'member1'); /* 1, 'key1' => {'member1'} */
$vedis->sAdd('key1' , 'member2', 'member3'); /* 2, 'key1' => {'member1', 'member2', 'member3'}*/
$vedis->sAdd('key1' , 'member2'); /* 1, 'key1' => {'member1', 'member2', 'member3'}*/
Description: Returns the cardinality of the set identified by key.
key
LONG the cardinality of the set identified by key, 0 if the set doesn't exist.
$vedis->sAdd('key1' , 'member1');
$vedis->sAdd('key1' , 'member2');
$vedis->sAdd('key1' , 'member3'); /* 'key1' => {'member1', 'member2', 'member3'}*/
$vedis->sCard('key1'); /* 3 */
$vedis->sCard('keyX'); /* 0 */
Description: Performs the difference between N sets and returns it.
keys: key1, key2, ... , keyN: Any number of keys corresponding to sets.
Array of strings: The difference of the first set will all the others.
$vedis->sAdd('s0', '1');
$vedis->sAdd('s0', '2');
$vedis->sAdd('s0', '3');
$vedis->sAdd('s0', '4');
$vedis->sAdd('s1', '1');
$vedis->sAdd('s2', '3');
var_dump($vedis->sDiff('s0', 's1', 's2'));
Return value: all elements of s0 that are neither in s1 nor in s2.
array(2) {
[0]=>
string(1) "2"
[1]=>
string(1) "4"
}
Description: Returns the members of a set resulting from the intersection of all the sets held at the specified keys.
If just a single key is specified, then this command produces the members of
this set. If one of the keys is missing, FALSE
is returned.
key1, key2, keyN: keys identifying the different sets on which we will apply the intersection.
Array, contain the result of the intersection between those keys. If the intersection beteen the different sets is empty, the return value will be empty array.
$vedis->sAdd('key1', 'val1');
$vedis->sAdd('key1', 'val2');
$vedis->sAdd('key1', 'val3');
$vedis->sAdd('key1', 'val4');
$vedis->sAdd('key2', 'val3');
$vedis->sAdd('key2', 'val4');
$vedis->sAdd('key3', 'val3');
$vedis->sAdd('key3', 'val4');
var_dump($vedis->sInter('key1', 'key2', 'key3'));
Output:
array(2) {
[0]=>
string(4) "val3"
[1]=>
string(4) "val4"
}
Description: Checks if value
is a member of the set stored at the key
key
.
key value
BOOL TRUE
if value
is a member of the set at key key
, FALSE
otherwise.
$vedis->sAdd('key1' , 'member1');
$vedis->sAdd('key1' , 'member2');
$vedis->sAdd('key1' , 'member3'); /* 'key1' => {'member1', 'member2', 'member3'}*/
$vedis->sIsMember('key1', 'member1'); /* TRUE */
$vedis->sIsMember('key1', 'memberX'); /* FALSE */
Description: Returns the contents of a set.
Key: key
An array of elements, the contents of the set.
$vedis->sAdd('s', 'a');
$vedis->sAdd('s', 'b');
$vedis->sAdd('s', 'a');
$vedis->sAdd('s', 'c');
var_dump($vedis->sMembers('s'));
Output:
array(3) {
[0]=>
string(1) "a"
[1]=>
string(1) "b"
[2]=>
string(1) "c"
}
Description: Removes and returns a random element from the set value at Key.
key
String "popped" value
Bool FALSE
if set identified by key is empty or doesn't exist.
$vedis->sAdd('key1' , 'member1');
$vedis->sAdd('key1' , 'member2');
$vedis->sAdd('key1' , 'member3'); /* 'key1' => {'member1', 'member2', 'member3'}*/
$vedis->sPop('key1'); /* member3, 'key1' => {'member1', 'member2'} */
$vedis->sPop('key1'); /* member2, 'key1' => {'member1'} */
Description: Removes the specified member from the set value stored at key.
key member
LONG The number of elements removed from the set.
$vedis->sAdd('key1' , 'member1');
$vedis->sAdd('key1' , 'member2');
$vedis->sAdd('key1' , 'member3'); /* 'key1' => {'member1', 'member2', 'member3'}*/
$vedis->sRem('key1', 'member2', 'member3'); /* 2. 'key1' => {'member1'} */
Description: Get the last element in a set
key
String "popped" value
Bool FALSE
if set identified by key is empty or doesn't exist.
$vedis->sAdd('key1' , 'member1');
$vedis->sAdd('key1' , 'member2');
$vedis->sAdd('key1' , 'member3'); /* 'key1' => {'member1', 'member2', 'member3'}*/
$vedis->sPeek('key1'); /* member3, 'key1' => {'member1', 'member2'} */
$vedis->sPeek('key1'); /* member2, 'key1' => {'member1'} */
Description: Get the first element in a set
key
String "popped" value
Bool FALSE
if set identified by key is empty or doesn't exist.
$vedis->sAdd('key1' , 'member1');
$vedis->sAdd('key1' , 'member2');
$vedis->sAdd('key1' , 'member3'); /* 'key1' => {'member1', 'member2', 'member3'}*/
$vedis->sTop('key1'); /* member3, 'key1' => {'member1', 'member2'} */
$vedis->sTop('key1'); /* member2, 'key1' => {'member1'} */
- begin - Start a write transaction
- commit - Commit an active write transaction
- rollback - Rollback an active write transaction
- cmdList - List of installed vedis commands
- eval - Execute one or more Vedis commands
- credits - Expand the vedis signature and copyright notice
Description: Start a write transaction
Bool TRUE
if the command is successful.
Description: Commit an active write transaction
Bool TRUE
if the command is successful.
Description: Rollback an active write transaction
Bool TRUE
if the command is successful.
Description: List of installed vedis commands
Array: Array of installed vedis commands
Description: Execute one or more Vedis commands
STRING: command
Execution result of the command.
$vedis->eval('SET key value; GET key'); /* value */
Description: Expand the vedis signature and copyright notice
String: Expand the vedis signature and copyright notice
- Serializer