marow-dev/redis-connector

0.2.0 2016-08-11 20:15 UTC

This package is not auto-updated.

Last update: 2024-05-11 17:12:34 UTC


README

Redis client

Connecting to redis

$connection = RedisConnector\Connection();

If connection cant be established RedisConnector\ConnectorException is thrown.

Default connection parameters are:

hostname: localhost

port: 6379

Client

$client = new RedisConnector\Client(new RedisConnector\Connection());

Sending commands to redis

$client = new RedisConnector\Client(new RedisConnector\Connection());
$client->set('key', 'value');

Most popular commands are methods in RedisConnector\Client class (get, set, etc.). You can issue other commands by using RedisConnector\Client object (class RedisConnector\Client implements magic method __call).

Exceptions Codes

  • 10000 - Connection cannot be established
  • 10001 - Not connected to redis
  • 10002 - Response read error
  • 10003 - Error generated by Redis
  • 10004 - Command send error
  • 10100 - No response method
  • 10200 - Data is not an object
  • 10201 - Data is not an array
  • 10202 - Wrong key

Example

try {
  $client = new RedisConnector\Client(new RedisConnector\Connection());
  $client->set('test', 'value of key test');
  $testValue = $client->get('test');
} catch ($e RedisConnector\ConnectorException) {
  var_dump($e);
}