Redislabs RedisJSON aka ReJSON Module Client for PHP that supports Predis and PhpRedis

2.1 2022-12-10 20:10 UTC

This package is auto-updated.

Last update: 2023-03-10 21:13:28 UTC


RedisJSON-PHP provides a client for Redislabs' ReJSON Module for PHP. This library supports both widely used redis clients (PECL Redis Extension and Predis).

Build Status Coverage Status Scrutinizer Code Quality Latest Stable Version Total Downloads Latest Unstable Version License

About RedisJSON

"RedisJSON is a Redis module that implements ECMA-404 The JSON Data Interchange Standard as a native data type. It allows storing, updating and fetching JSON values from Redis keys (documents)".

More info about RedisJSON.

RedisJSON-PHP Interface

Commanda are named after lowercase version of the original RedisJSON commands.


use Redislabs\Interfaces\ModuleInterface;
use Predis\ClientInterface as PredisClient;
use Redis as PhpRedisClient;

interface RedisJsonInterface extends ModuleInterface
    public function set(string $key, string $path, $json, ?string $existentialModifier = null);
    public function get(...$arguments);
    public function del(string $key, ?string $path = '.'): int;
    public function forget(string $key, ?string $path = '.'): int;
    public function mget(...$arguments);
    public function type(string $key, ?string $paths = '.');
    public function numincrby(string $key, string $path, int $incrementBy);
    public function nummultby(string $key, string $path, int $multiplyBy);
    public function strappend(string $key, $json, ?string $path = '.');
    public function strlen(string $key, ?string $path = '.');
    public function arrappend(string $key, string $path, ...$jsons);
    public function arrindex(string $key, string $path, $json, ?int $start = 0, ?int $stop = 0);
    public function arrinsert(string $key, string $path, int $index, ...$jsons);
    public function arrlen(string $key, string $path = '.');
    public function arrpop(string $key, ?string $path = '.', ?int $index = -1);
    public function arrtrim(string $key, $path, ?int $start = 0, ?int $stop = 0);
    public function objkeys(string $key, ?string $path = '.');
    public function objlen(string $key, ?string $path = '.');
    public function debug(string $subcommand, ?string $key = null, ?string $path = '.');
    public function resp(string $key, ?string $paths = '.');
    public function getClient();
    public function raw(string $command, ...$arguments);
    public static function createWithPredis(PredisClient $client);
    public static function createWithPhpRedis(PhpRedisClient $client);


The recommended method to install RedisJSON-PHP for ReJSON is with composer.

composer require mkorkmaz/redislabs-rejson

If you use Redis ReJSON module version 1.0:

composer require mkorkmaz/redislabs-rejson:"^1.0"


You need PECL Redis Extension or Predis to use ReJSON-PHP.

Creating RedisJSON Client

Example for PECL Redis Extension

use Redis;
use Redislabs\Module\RedisJson\RedisJson;

$redisClient = new Redis();
$reJSON = ReJSON::createWithPhpRedis($redisClient);
Example for Predis

use Predis;
use Redislabs\Module\RedisJson\RedisJson;

$redisClient = new Predis\Client();
$redisJson = RedisJson::createWithPredis($redisClient);

Running commands

  • $key (or $keys - array that containes $key items) parameters are all string.
  • $json (or $jsons - array that containes $json items) parameters can be any type of json encodable data (array, int, string, stdClass, any JsonSerializable object etc...).
  • Commands automatically performs json encoding these data. Functions also returns json decoded data if the response is json string.

$redisJson->set('test', '.', ['foo'=>'bar'], 'NX');
$redisJson->set('test', '.baz', 'qux');
$redisJson->set('test', '.baz', 'quux', 'XX');
$redisJson->set('test2', '.', ['foo2'=>'bar2']);
$baz = $redisJson->get('test', '.baz');

// Prints string(4) "quux"
$array = $redisJson->get('test', '.');
Prints result as an array instead of an object
array(2) {
  string(3) "bar"
  string(4) "quux"

$array = $redisJson->mget('test', 'test2', '.');
Prints result as an associative array instead of an object
array(2) {
  array(2) {
    string(3) "bar"
    string(4) "quux"
  array(1) {
    string(3) "bar2"

Test and Development

You can use Docker Image provided by Redislabs.

docker run -p 6379:6379 redislabs/rejson:2.0.4