ptrofimov / tinyredisclient Goto Github PK
View Code? Open in Web Editor NEWTinyRedisClient - the most lightweight Redis client written in PHP
License: MIT License
TinyRedisClient - the most lightweight Redis client written in PHP
License: MIT License
I've tried this for ssdb, doesnt work with the error of title.
Can you help? What should I change?
Sometimes it returns 8192 length of binary data
other times it returns 16384 length of binary data
can you help? i think it's something to do with reading binary data or socket timeout or something?
How do you use multi and exec with tinyredisclient? Do you have an example usage?
I've tried the multi and exec... it "works" but i think i need to call the connection too many times...
e.g.
$redis->multi();
$redis->scard('a');
$redis->scard('b');
.
.
$redis->scard('z');
$values=$redis->exec();
but... it doesn't seem to send everything all at once?
Would like to have tinyssdbclient and twemproxy client
thanks in advance
e.g. as in predis
$array = new Predis_Client(array(
array('host' => '127.0.0.1','port' => 1000),
array('host' => '127.0.0.1','port' => 1001),
array('host' => '127.0.0.1','port' => 1002),
array('host' => '127.0.0.1','port' => 1003),
array('host' => '127.0.0.1','port' => 1004)
));
how can i make this...
$config = '127.0.0.1:1000';
$item = new TinyRedisClient($config);
to
$config = array('127.0.0.1:1000','127.0.0.1:1001','127.0.0.1:1002');
$item = new TinyRedisClient($config);
this php will be complete and excellent if this feature is added. please help. thanks.
Data is php serialized string. EG 'a:6:{s:7:"success";b:1;s:5:"total";s:1:"8";s:4:"data";a:8:{i:0;a:17..." etc
Data is 7169 bytes long. Returned as "RESP Bulk String"."
$line = fread($this->getSocket(), $result + 2); // FAILS TO RETURN 7171 bytes
Ask to read 7171 but get back ony 2888 bytes. So php unserialize fails.
Verify no timeout or blocking:
017-12-17 17:10:37
'META'
array (
'stream_type' => 'tcp_socket/ssl',
'mode' => 'r+',
'unread_bytes' => 0,
'seekable' => false,
'timed_out' => false, OK
'blocked' => true, OK
'eof' => false,
)
// This works. I get the full string (7169 bytes)
$line = fgets($this->getSocket());
So now I think this is ok provided I only use it for serialized string (never contain CRLF).
But I dunno why this is necessary.
It does not seem that there is a way to select a DB, then issue a command:
echo $redisClient->select(2);
echo $redisClient->get('key');
The select does return ok, but the subsequent get request looks for a key in DB 0. It would be nice to be able to specify the DB in the constructor.
Best,
-O
`
private $_socket;
public function __construct($address, $port)
{
$this->_socket = stream_socket_client($address.':'.$port);
}
public function __call($method, array $args)
{
array_unshift($args, $method);
$cmd = '*' . count($args) . "\r\n";
foreach ($args as $item) {
$cmd .= '$' . strlen($item) . "\r\n" . $item . "\r\n";
}
fwrite($this->_socket, $cmd);
return $this->_parseResponse();
}
private function _parseResponse()
{
$line = fgets($this->_socket);
list($type, $result) = array($line[0], substr($line, 1, strlen($line) - 3));
if ($type == '-') // error message
{
throw new TinyRedisClient_Exception($result);
} elseif ($type == '$') // bulk reply
{
if ($result == -1)
$result = null;
else {
$line = fread($this->_socket, $result + 2);
$result = substr($line, 0, strlen($line) - 2);
}
} elseif ($type == '*') // multi-bulk reply
{
$count = ( int ) $result;
for ($i = 0, $result = array(); $i < $count; $i++) {
$result[] = $this->_parseResponse();
}
}
return $result;
}
`
the problem here is that I don't know where the fwrite() function writes my file does it create an actual file or does it write to the stream resource I don't know, when I try this on my local machine it works fine and the command sent to my database but after I moved to docker this line $line = fgets($this->_socket); returns a false which means there is no data has been written or some error happened, I am expecting the written command to the stream
I found out that if you change line 43 from:
: ($this->socket = stream_socket_client($this->server));
to
: ($this->socket = stream_socket_client($this->server, $errorno, $errorstr, NULL, STREAM_CLIENT_PERSISTENT));
connection will stay alive and it will work much faster in sequential requests.
What's the example for unix socket connection?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.