|Last Updated||Ratings||Unique User Downloads||Download Rankings|
|2017-06-29 (2 years ago)||74%||Total: 145||All time: 8,836 This week: 328|
|zhandlesocket 1.0.5||MIT/X Consortium ...||5||Networking, Zephir|
This package can access MySQL tables as NoSQL with HandlerSocket.
Another PHP extension for communicating with handlersocket. Built with Zephir: https://github.com/phalcon/zephir. Thus, you will have to install Zephir first to build zhandlersocket. Once you have Zephir installed and cloned the zhandlersocket repo:
cd <zhandlersocket directory> zephir build
After that, under _ext/modules_ you will find the zhandlersocket.so. Copy it to your PHP's extension_dir, add "extension=zhandlersocket.so" to your php.ini and restart your web-server. Check with the following command if zhandlersocket is there:
The output should, among other lines, contain "zhandlersocket".
use \Zhandlersocket\Client; $client = new Client();// create a HS client with default connection parameters $index = $client->getIndex("test", "my_table", "PRIMARY", ["id", "name"]); // find() would return an array of rows, because an index is not always unique // In this case, we know there will be 1 or 0 rows with ID=10, so we use findFirst(), // which will fetch the very first row and return it $row = $index->findFirst(10); // Update a row: $upd = $index->updateById(10, ["id" => 10, "name" => "New name"]);// have to specify ALL columns
HandlerSocket enables you to use InnoDB table in a NoSQL way. HS performance when selecting by Primary Key is at least close to that of Memcached, and according to some benchmarks, HS is even faster. Given this, you might well give up on using Memcached in certain cases (and having all the assiciated headaches with cache invalidating).
HS operates on InnoDB indexes. That means that you always perform a query on a index. This might be the table's PRIMARY KEY but it also may be any other index you have on the table.
In order to perform queries with ZhandlerSocket, you first need to instantiate ZhandlerSocket\Client:
$client = new Client("localhost", 9998, 9999);
Above are the default connection parameters, and you could as well omit them.
When you have a Client instance, you might want to create an instance of ZhandlerSocket\Index:
$index = $client->getIndex("test", "my_table", "PRIMARY", ["id", "name"]);
This code means that you would like to speak Handlersocket with InnoDB table my_table from database test. You will perform you find queries using PRIMARY KEY, and you would like to receive in response the foloowing columns: id and name.
PRIMARY KEY is not the only capability. Suppose you have a table movie, which has fields id, genre, title, view_count. PRIMARY KEY is id but there is also a key on genre column called genre_key. Eventually, the index might well be named exactly as the column but don't be confused: when opening a HS index, you need the index name, not the column name.
$index = $client->getIndex("test", "movie", "genre_key", ["id", "genre", "title", "view_count"]);
ZhandlerSocket\Client->getIndex() method accepts an optional 5th parameter which is filter columns. This specifies columns that you want to support additional filtering for. Those do not necessarily have to be a part of index but they have to be a part of columns you chose for selection (4th argument).
Basic usage of HS is to select a row by key, update a row, delete a row. ZhandlerSocket\Index class has the following to offer for the basic find-by-key functionality:
However, ZhandlerSocket\Index has also more to offer. HandlerSocket provides one with robust tools for quickly finding rows in a InnoDB table. Zhandlersocket ships with WhereClause class which enables you to specify criteria you want to apply to the selection.
WhereClause class is responsible for filtering and setting limits for selection from HS. HS is not only capable of selecting a single row by PRIMARY KEY, but also of selecting multiple rows based on criteria. Basic usage:
// We have an index on "counter" column, and we want to find up to 10 rows with counter > 20 $index = $client->getIndex("test", "test", "counter_idx", ["id", "counter"]); $rows = $index->createWhereClause(">", 20)->setLimit(10)->find();
You can also perform some filtering of the results with WhereClause->addFilter(). This is _post-filtering_ which occurs on the result set obtained from index. Filtering can be done on all columns specified as fcols argument whe creating the index.
|Version Control||Unique User Downloads||Download Rankings|