PHPackages                             jpbourbon/redisgraph\_php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. jpbourbon/redisgraph\_php

ActiveLibrary[Database &amp; ORM](/categories/database)

jpbourbon/redisgraph\_php
=========================

RedisGraph php client

v0.5.8(6y ago)5372[2 issues](https://github.com/jpbourbon/redisgraph_php/issues)[1 PRs](https://github.com/jpbourbon/redisgraph_php/pulls)MITPHPPHP &gt;=7.0

Since Nov 8Pushed 6y ago2 watchersCompare

[ Source](https://github.com/jpbourbon/redisgraph_php)[ Packagist](https://packagist.org/packages/jpbourbon/redisgraph_php)[ Docs](https://github.com/jpbourbon/redisgraph_php)[ RSS](/packages/jpbourbon-redisgraph-php/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (1)Versions (11)Used By (0)

redisgraph\_php
===============

[](#redisgraph_php)

A client for RedisGraph aiming to track its development and implementation of OpenCypher. The goal of this library is providing a standard way of sending queries to the RedisGraph engine and encapsulate the results in a clean object.

Installation
------------

[](#installation)

```
composer require jpbourbon/redisgraph_php:"0.5.8"

```

Usage
-----

[](#usage)

There are 2 ways of using this library.

- Using the **Client**, an instantiable class;
- Using **RedisGraph**, a static wrapper that loads the Client as a singleton;

### Connection

[](#connection)

#### Client

[](#client)

```
...
use RedisGraphPhp\Client;
...
$options = [
    "host"  => "127.0.0.1",
    "port"  => "6379",
    "graph" => "test"
];
$client = new Client($options);

```

#### RedisGraph

[](#redisgraph)

```
...
use RedisGraphPhp\RedisGraph;
...
$options = [
    "host"  => "127.0.0.1",
    "port"  => "6379",
    "graph" => "test"
];
RedisGraph::setOptions($options);

```

### Queries

[](#queries)

This library supports only raw queries. However, we encapsulate the query in a **Cypher** class that can be used for validation in future iterations. This class also provides tagging and runtime changing of graphs.

```
...
use RedisGraphPha\Cypher;
...
$cypher = new Cypher("MATCH (f:Foo) RETURN f", "MyTast");

```

### Running queries

[](#running-queries)

#### Client

[](#client-1)

```
...
use RedisGraphPhp\Client;
use RedisGraphPha\Cypher;
...
$options = [
    "host"  => "127.0.0.1",
    "port"  => "6379",
    "graph" => "test"
];
$client = new Client($options);
$cypher = new Cypher("MATCH (f:Foo) RETURN f", "MyTast");
$result = $client->run($cypher);

```

#### RedisGraph

[](#redisgraph-1)

```
...
use RedisGraphPhp\RedisGraph;
use RedisGraphPha\Cypher;
...
$options = [
    "host"  => "127.0.0.1",
    "port"  => "6379",
    "graph" => "test"
];
RedisGraph::setOptions($options);
$cypher = new Cypher("MATCH (f:Foo) RETURN f", "MyTast");
$result = RedisGraph::run($cypher);

```

### Results

[](#results)

The response from the ***run*** method will return an instance of the ***Result*** class. This class consists of a structure that holds an array of query return ***keys***, and array of ***RecordSets*** with ***Records***\*, the ***Cypher*** object and the ***Statistics*** object.

#### Return keys

[](#return-keys)

A Cypher query that contains a ***RETURN*** clause will always return a key:value pair, except when the query generates no returnable values. Consider the following Cypher query:

```
MATCH (f:Foo) RETURN f

```

This returns the key ***f***. To obtain an array with the returned keys, use the ***getKeys*** method:

```
$result->getKeys();

```

#### Getting the RecordSet and Records

[](#getting-the-recordset-and-records)

The \***Result** and ***RecordSet*** objects provide methods to lookup their child classes.

```
$result->getRecordSets(); // Returns all RecordSet objects returnes (rows)
$result->getRecordSet(N); // Returns the RecordSet at position N or null
$result->firstRecordSet(); // Returns the first RecordSet or null
$result->size(); // Returns the size of the recordSets array

$result->firstRecordSet()->getRecords(); // Returns all Records from the first RecordSet
$result->firstRecordSet()->getRecord(N); // Returns the Record at position N or null
$result->firstRecordSet()->firstRecord(); // Returns the first Records from the RecordSet

```

#### Types of Records

[](#types-of-records)

The ***Records*** can be either ***Nodes***, ***Relationships*** or ***Scalar values***. Each of them has its own characteristics, reflected in the returned object. The distinct types of record can be easily identified using the ***getRecordType*** method:

```
$result->firstRecordSet()->firstRecord()->getRecordType(); // Returns the record type as a string

```

#### Scalar

[](#scalar)

Scalar values are single values. Those can be either the result of an internal cypher function (such as ***SUM(), COUNT()*** etc) or the value from a node or relationship property.

```
MATCH (n) RETURN COUNT(n) AS total // "total" is a scalar value
MATCH (n) RETURN n.key // "n.key" is a scalar value

```

To access the value you would first need to know the key, and use the ***getValue()*** method on the record:

```
$result->firstRecordSet()->getRecord("total")->getValue(); // Returns the single value

```

However, as we often need to get a list of scalar values, there is a special method for that:

```
$result->getAllScalar("n.key"); // Returns an array of all values from all recordsets

```

#### Nodes and Relationships

[](#nodes-and-relationships)

***Nodes*** and ***Relationships*** share some common methods, since they can both hold properties, but have their specific ones. Common

```
$result->firstRecordSet()->firstRecord()->getId(); // returns the internal id of the record
$result->firstRecordSet()->firstRecord()-getProperties(); // Gets an array with existing properties;
$result->firstRecordSet()->firstRecord()->getValue($property); // Gets the value for the given property name

```

Nodes

```
$result->firstRecordSet()->firstRecord()->getLabels(); // Gets the array of labels

```

Relationship

```
$result->firstRecordSet()->firstRecord()->getType(); // Returns the type as a string
$result->firstRecordSet()->firstRecord()->getLinkedNodes(); // Gets an array with the source and target node ids

```

### Graphs

[](#graphs)

RedisGraph supports multiple graphs running alongside. This means the client must be flexible and support the different graphs. This client allows the definition of the graph in 3 different places: 1 - connection options; 2 - cypher object; 3 - chained method before running the query; The graph defined in the connection options is the default graph, and acts as a fallback in case no graph is defined anywhere else. The graph defined on the cypher query or the chained method is always considered secondary, and must be explicitely set to be used.

#### 1 - Connection options

[](#1---connection-options)

simply define the graph in the array:

```
 $options = [
    "host"  => "127.0.0.1",
    "port"  => "6379",
    "graph" => "test"
];

```

#### 2 - Cypher query

[](#2---cypher-query)

The graph is an optional argument when creating the Cypher object. If defined, overrides the default graph for the query execution.

```
$cypher = new Cypher("MATCH (f:Foo) RETURN f", "MyTast", "myOtherGraph);

```

#### 3 - Chained method

[](#3---chained-method)

This option is useful if the user intends to use the same Cypher object for different graphs, as it overrides both the default graph and the Cypher object graph:

##### Client

[](#client-2)

```
...
$cypher = new Cypher("MATCH (f:Foo) RETURN f", "MyTast", "myOtherGraph");
$result = $client->graph("myAlternativeGraph")->run($cypher);

```

##### RedisGraph

[](#redisgraph-2)

```
...
$cypher = new Cypher("MATCH (f:Foo) RETURN f", "MyTast", "myOtherGraph");
$result = RedisGraph::graph("myAlternativeGraph")::run($cypher);

```

### Delete graphs

[](#delete-graphs)

Graphs can be deleted with a simple ***delete*** method:

##### Client

[](#client-3)

```
...
$result = $client)->delete("myGraph");

```

##### RedisGraph

[](#redisgraph-3)

```
...
$result = RedisGraph::delete("myGraph");

```

### Explain queries

[](#explain-queries)

Both the ***RedisGraph*** and the ***Client*** classes feature an ***explain*** method that returns the query analysis:

#### Client

[](#client-4)

```
...
use RedisGraphPhp\Client;
use RedisGraphPha\Cypher;
...
$options = [
    "host"  => "127.0.0.1",
    "port"  => "6379",
    "graph" => "test"
];
$client = new Client($options);
$cypher = new Cypher("MATCH (f:Foo) RETURN f", "MyTast");
$result = $client->explain($cypher);

```

#### RedisGraph

[](#redisgraph-4)

```
...
use RedisGraphPhp\RedisGraph;
use RedisGraphPha\Cypher;
...
$options = [
    "host"  => "127.0.0.1",
    "port"  => "6379",
    "graph" => "test"
];
RedisGraph::setOptions($options);
$cypher = new Cypher("MATCH (f:Foo) RETURN f", "MyTast");
$result = RedisGraph::explain($cypher);

```

TBC...
------

[](#tbc)

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance12

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

10

Last Release

2380d ago

PHP version history (2 changes)v0.0.1PHP ^7.2

v0.5.4PHP &gt;=7.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6758910?v=4)[jpbourbon](/maintainers/jpbourbon)[@jpbourbon](https://github.com/jpbourbon)

---

Top Contributors

[![jpbourbon](https://avatars.githubusercontent.com/u/6758910?v=4)](https://github.com/jpbourbon "jpbourbon (24 commits)")

---

Tags

cyphergraphredisgraphtphp

### Embed Badge

![Health badge](/badges/jpbourbon-redisgraph-php/health.svg)

```
[![Health](https://phpackages.com/badges/jpbourbon-redisgraph-php/health.svg)](https://phpackages.com/packages/jpbourbon-redisgraph-php)
```

###  Alternatives

[graphaware/neo4j-common

Common Utilities library for Neo4j

24876.2k24](/packages/graphaware-neo4j-common)[neo4j/neo4j-bundle

Symfony integration for Neo4j

8272.1k](/packages/neo4j-neo4j-bundle)[stefanak-michal/bolt

PHP library to provide connectivity to graph database over TCP socket with Bolt specification

79655.8k8](/packages/stefanak-michal-bolt)[wikibase-solutions/php-cypher-dsl

A query builder for the Cypher query language

1853.4k4](/packages/wikibase-solutions-php-cypher-dsl)[onurb/doctrine-yuml-bundle

Symfony Bundle to visualize the mapping of your entities with Yuml

4198.6k](/packages/onurb-doctrine-yuml-bundle)[rolfvreijdenberger/izzum-statemachine

A superior statemachine library php &gt;= 5.3. Integrates with your domain models perfectly.

7425.5k](/packages/rolfvreijdenberger-izzum-statemachine)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
