Tarantool is a development of Mail.ru. Represents a high-performance key / value no-Sql solution. The lack of ports for popular programming languages inhibits the popularity of this database. Tried to fill this gap.namespace [ 0 ] . enabled = 1
namespace [ 0 ] . index [ 0 ] . type = "HASH"
namespace [ 0 ] . index [ 0 ] . unique = 1
namespace [ 0 ] . index [ 0 ] . key_field [ 0 ] . fieldno = 0
namespace [ 0 ] . index [ 0 ] . key_field [ 0 ] . type = "NUM"
')
namespace [ 0 ] . index [ 1 ] . type = "TREE"
namespace [ 0 ] . index [ 1 ] . unique = 0
namespace [ 0 ] . index [ 1 ] . key_field [ 0 ] . fieldno = 1
namespace [ 0 ] . index [ 1 ] . key_field [ 0 ] . type = "STR"
namespace [ 0 ] . index [ 2 ] . type = "TREE"
namespace [ 0 ] . index [ 2 ] . unique = 0
namespace [ 0 ] . index [ 2 ] . key_field [ 0 ] . fieldno = 1
namespace [ 0 ] . index [ 2 ] . key_field [ 0 ] . type = "STR"
namespace [ 0 ] . index [ 2 ] . key_field [ 1 ] . fieldno = 2
namespace [ 0 ] . index [ 2 ] . key_field [ 1 ] . type = "STR"
namespace [ 0 ] . index [ 3 ] . type = "HASH"
namespace [ 0 ] . index [ 3 ] . unique = 0
namespace [ 0 ] . index [ 3 ] . key_field [ 0 ] . fieldno = 3
namespace [ 0 ] . index [ 3 ] . key_field [ 0 ] . type = "NUM"
1) :
** git clone git@github.com:akalend/tarantool.git
master https://github.com/mailru/tarantool.git
2) cd connector/php
3) phpize
4) ./configure
5) sudo make install
6) php.ini extension :
extension=tarantool.so
// constructor (host, port);
$ tnt = new Tarantool ( $ host , $ port ) ;
In mathematics, a tuple is a sequence of a finite number of elementsIn PHP, a tuple is represented as an array.
In some programming languages (for example, Python or Lisp), a tuple is a special type of data structure.
© Wikipedia
$ tuple = array ( 1 , 'x' , 'abd' , 1023 ) ;
$ res = $ tnt -> insert ( 0 , $ tuple ) ;
var_dump ( $ res ) ;
/ **
* Tarantool :: select
*
* @param number namespace
* @param number index No
* @param mixed key
* @param optional limit default all
* @param optional offset default 0
*
* @return count of tuples
* /
$ count = $ tnt -> select ( 0 , 0 , 1 ) ; // namespace, index, key
var_dump ( $ count ) ;
$ res = $ tnt -> getTuple ( ) ;
var_dump ( $ res ) ;
echo "some tuple select by fielNo [1] = 'x' \ n " ;
$ count = $ tnt -> select ( 0 , 1 , 'x' ) ; // namespace, index, key
while ( ( $ res = $ tnt -> getTuple ( ) ) ! = false ) {
var_dump ( $ res ) ;
}
echo "some tuple select by index = 2 (fielNo [1] = 'spb' and fielNo [2] = 'realry') \ n " ;
$ count = $ tnt -> select ( 0 , 2 , array ( 'spb' , 'realty' ) ) ; // namespace, index, key
while ( ( $ res = $ tnt -> getTuple ( ) ) ! = false ) {
var_dump ( $ res ) ;
}
echo "some tuple select by index = 3 (fielNo [3] = 1025) \ n " ;
$ res = $ tnt -> select ( 0 , 3 , 1025 ) ; // namespace, index, key
var_dump ( $ res ) ;
while ( ( $ res = $ tnt -> getTuple ( ) ) ! = false ) {
var_dump ( $ res ) ;
}
echo "some tuple select by index = 3 (fielNo [3] = 1025) NEXT 5 (offset = 10, limit = 5) \ n " ;
$ tnt -> select ( 0 , 3 , 1025 , 5 , 10 ) ; // namespace, index, key, limit, offset
while ( ( $ res = $ tnt -> getTuple ( ) ) ! = false ) {
var_dump ( $ res ) ;
}
/ **If we want to decrease by 1, then we use:
* Tarantool :: inc
*
* @param namespace
* @param primary key
* @param field No for increment
* @param optional incremental data default +1
*
* @return bool result
* /
// increment
$ tnt -> inc ( 0 , 1 , 3 ) ;
$ tnt -> select ( 0 , 0 , 1 ) ;
$ tuple = $ tnt -> getTuple ( ) ;
var_dump ( $ tuple ) ;
$ tnt -> inc ( 0 , 1 , 3 , - 1 ) ;
/ **The second parameter is the selection key, the third parameter is the associative array of data that must be replaced. The keys of the array are the numeric indices corresponding to the numbers of the fields that need to be replaced with the data that correspond to the given keys.
* Tarantool :: update
*
* @param namespace
* @param primary key
* @param array of new data:
* array (fieldNo => newValue, ...)
*
* @return bool result
* /
$ res = $ tnt -> update ( 0 , 1 , array ( 2 => 'y' ) ) ;
echo "update tuple res = $ res \ n " ;
Source: https://habr.com/ru/post/122054/
All Articles