PHPackages                             palicao/php-redis-time-series - 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. [Caching](/categories/caching)
4. /
5. palicao/php-redis-time-series

ActiveLibrary[Caching](/categories/caching)

palicao/php-redis-time-series
=============================

Use Redis Time Series in PHP

2.1.1(5y ago)3333.0k↓32.2%13[5 issues](https://github.com/palicao/phpRedisTimeSeries/issues)[3 PRs](https://github.com/palicao/phpRedisTimeSeries/pulls)MITPHPPHP &gt;=7.2.0CI failing

Since Oct 11Pushed 2y ago7 watchersCompare

[ Source](https://github.com/palicao/phpRedisTimeSeries)[ Packagist](https://packagist.org/packages/palicao/php-redis-time-series)[ RSS](/packages/palicao-php-redis-time-series/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (7)Dependencies (2)Versions (16)Used By (0)

phpRedisTimeSeries
==================

[](#phpredistimeseries)

Use [Redis Time Series](https://oss.redislabs.com/redistimeseries/) in PHP!

[![Maintainability](https://camo.githubusercontent.com/e9960c60d3c5ffb436b8c9f45adaf9027e7f77a47dccea01f2cb88bcd169fda5/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f66656139323762393033373864643633613964382f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/palicao/phpRedisTimeSeries/maintainability)[![Test Coverage](https://camo.githubusercontent.com/32d4a3ab332f9a589740c0128eddc6939589b293ecfb133399ec5b3536e786cd/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f66656139323762393033373864643633613964382f746573745f636f766572616765)](https://codeclimate.com/github/palicao/phpRedisTimeSeries/test_coverage)[![Build Status](https://github.com/palicao/phpRedisTimeSeries/actions/workflows/main.yml/badge.svg)](https://travis-ci.com/palicao/phpRedisTimeSeries)[![Latest Stable Version](https://camo.githubusercontent.com/24b90fc217d98bf4b985f5d5a995f14789b2b45b9a205c241e0bd05cc33fbc25/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f70616c6963616f2f7068702d72656469732d74696d652d7365726965732e737667)](https://packagist.org/packages/palicao/php-redis-time-series)[![PHP version](https://camo.githubusercontent.com/be3d80254fa630b896664c12b2bdca8f4a1160da546ec9cc64f6d855602d3f68/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f70616c6963616f2f7068702d72656469732d74696d652d7365726965732f322e302e30)](https://camo.githubusercontent.com/be3d80254fa630b896664c12b2bdca8f4a1160da546ec9cc64f6d855602d3f68/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f70616c6963616f2f7068702d72656469732d74696d652d7365726965732f322e302e30)[![GitHub](https://camo.githubusercontent.com/808e0cc77ec482394bc4b13d634af393e09a951615bd32c1ed92ced132469d60/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f70616c6963616f2f706870526564697354696d65536572696573)](https://camo.githubusercontent.com/808e0cc77ec482394bc4b13d634af393e09a951615bd32c1ed92ced132469d60/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f70616c6963616f2f706870526564697354696d65536572696573)

Getting up and running
----------------------

[](#getting-up-and-running)

### Install

[](#install)

`composer require palicao/php-redis-time-series`

### Requirements

[](#requirements)

The library is tested against:

- PHP 7.2, 7.3, 7.4, 8.0
- RedisTimeSeries 1.4.10 (but it should work with any 1.4 version)

In order to use RedisTimeSeries 1.2 please use version 2.1.1 of this library.

### Construct

[](#construct)

```
$ts = new TimeSeries(
    new RedisClient(
        new Redis(),
        new RedisConnectionParams($host, $port)
    )
);

```

`TimeSeries` methods
--------------------

[](#timeseries-methods)

### `create`

[](#create)

`TimeSeries::create(string $key, ?int $retentionMs = null, array $labels = []): void`

Creates a key, optionally setting a retention time (in milliseconds) and some labels.

See .

### `alter`

[](#alter)

`TimeSeries::alter(string $key, ?int $retentionMs = null, array $labels = []): void`

Modifies an existing key's retention time and/or labels.

See .

### `add`

[](#add)

`TimeSeries::add(Sample $sample, ?int $retentionMs = null, array $labels = []): Sample`

Adds a sample.

If the key was not explicitly `create`d, it's possible to set retention and labels.

See .

Examples:

- `$sample = $ts->add(new Sample('myKey', 32.10), 10, [new Label('myLabel', 'myValue')]);` Adds a sample to `myKey` at the current timestamp (time of the redis server) and returns it (complete with dateTime).
- `$sample = $ts->add(new Sample('myKey', 32.10, new DateTimeImmutable()), 10, [new Label('myLabel', 'myValue')]);`Adds a sample to `myKey` at a given datetime and returns it.

Please notice that RedisTimeSeries only allows to add samples in order (no sample older than the latest is allowed)

### `addMany`

[](#addmany)

`TimeSeries::addMany(array $samples): array`

Adds several samples.

As usual, if no timestamp is provided, the redis server current time is used. Added samples are returned in an array.

See .

### `incrementBy` and `decrementBy`

[](#incrementby-and-decrementby)

`TimeSeries::incrementBy(Sample $sample, ?int $resetMs = null, ?int $retentionMs = null, array $labels = []): void`

`TimeSeries::decrementBy(Sample $sample, ?int $resetMs = null, ?int $retentionMs = null, array $labels = []): void`

Add a sample to a key, incrementing or decrementing the last value by an amount specified in `$sample`. The value can be optionally reset after `$resetMs` milliseconds.

Similarly to `add`, if the command is used on a non-existing key, it's possible to set retention and labels.

See .

### `createRule`

[](#createrule)

`TimeSeries::createRule(string $sourceKey, string $destKey, AggregationRule $rule): void`

Creates an aggregation rule which applies the given `$rule` to `$sourceKey` in order to populate `$destKey`.

Notice that both key must already exist otherwise the command will fail.

See .

Example:

- `$ts->createRule('source', 'destination', new AggregationRule(AggregationRule::AVG, 10000)`, will populate the `destination` key by averaging the samples contained in `source` over 10 second buckets.

### `deleteRule`

[](#deleterule)

`TimeSeries::deleteRule(string $sourceKey, string $destKey): void`

Deletes an existing aggregation rule.

See .

### `range`

[](#range)

`TimeSeries::range(string $key, ?DateTimeInterface $from = null, ?DateTimeInterface $to = null, ?int $count = null, ?AggregationRule $rule = null, bool $reverse = false): Sample[]`

Retrieves samples from a key. It's possible to limit the query in a given time frame (passing `$from` and `$to`), to limit the retrieved amount of samples (passing `$count`), and also to pre-aggregate the results using a `$rule`.

The flag `$reverse` will return the results in reverse time order.

See .

### `multiRange` and `multiRangeWithLabels`

[](#multirange-and-multirangewithlabels)

`TimeSeries::multiRange(Filter $filter, ?DateTimeInterface $from = null, ?DateTimeInterface $to = null, ?int $count = null, ?AggregationRule $rule = null, bool $reverse = false): Sample[]`

`TimeSeries::multiRangeWithLabels(Filter $filter, ?DateTimeInterface $from = null, ?DateTimeInterface $to = null, ?int $count = null, ?AggregationRule $rule = null, bool $reverse = false): SampleWithLabels[]`

Similar to `range`, but instead of querying by key, queries for a specific set of labels specified in `$filter`.

`multiRangeWithLabels` will return an array of `SampleWithLabels` instead of simple `Sample`s.

The flag `$reverse` will return the results in reverse time order.

See .

### `getLastSample`

[](#getlastsample)

`TimeSeries::getLastSample(string $key): Sample`

Gets the last sample for a key.

See .

### `getLastSamples`

[](#getlastsamples)

`TimeSeries::getLastSamples(Filter $filter): Sample[]`

Gets the last sample for a set of keys matching a given `$filter`.

See .

### `info`

[](#info)

`TimeSeries::info(string $key): Metadata`

Gets useful metadata for a given key.

See .

### `getKeysByFilter`

[](#getkeysbyfilter)

`getKeysByFilter(Filter $filter): string[]`

Retrieves the list of keys matching a given `$filter`.

See .

Advanced connection parameters
------------------------------

[](#advanced-connection-parameters)

You can manipulate your `RedisConnectionParams` using the following methods:

- `RedisConnectionParams::setPersistentConnection(bool $persistentConnection)` enable/disable a persistent connection
- `RedisConnectionParams::setTimeout(int $timeout)` connection timeout in seconds
- `RedisConnectionParams::setRetryInterval(int $retryInterval)` retry interval in seconds
- `RedisConnectionParams::setReadTimeout(float $readTimeout)` read timeout in seconds

Building Filters
----------------

[](#building-filters)

A `Filter` is composed of multiple filtering operations. At least one equality operation must be provided (in the constructor). Adding filtering operations can be chained using the method `add`.

Examples:

- `$f = (new Filter('label1', 'value1'))->add('label2', Filter::OP_EXISTS);` filters items which have label1 = value1 and have label2.
- `$f = (new Filter('label1', 'value1'))->add('label2', Filter::OP_IN, ['a', 'b', 'c']);` filters items which have label1 = value1 and where label2 is one of 'a', 'b' or 'c'.

Local testing
-------------

[](#local-testing)

For local testing you can use the provided `docker-compose.yml` file, which will create a PHP container (with the redis extension pre-installed), and a redis container (with Redis Time Series included).

Contributors
------------

[](#contributors)

Thanks [Mrkisha](https://github.com/Mrkisha) for the precious contributions.

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity41

Moderate usage in the ecosystem

Community18

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 87.5% 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 ~29 days

Recently: every ~68 days

Total

14

Last Release

2121d ago

Major Versions

0.3.0 → 1.0.02019-11-06

1.1.2 → 2.0.02019-12-19

### Community

Maintainers

![](https://www.gravatar.com/avatar/29f2d2fba3b6f3b89c90f2d222ae67e62663a98b1fb8fd67bbfaa489da21e65e?d=identicon)[palicao](/maintainers/palicao)

---

Top Contributors

[![palicao](https://avatars.githubusercontent.com/u/659961?v=4)](https://github.com/palicao "palicao (35 commits)")[![Mrkisha](https://avatars.githubusercontent.com/u/1561303?v=4)](https://github.com/Mrkisha "Mrkisha (3 commits)")[![Laurent-Sarrazin](https://avatars.githubusercontent.com/u/1137846?v=4)](https://github.com/Laurent-Sarrazin "Laurent-Sarrazin (1 commits)")[![mstaack](https://avatars.githubusercontent.com/u/10169509?v=4)](https://github.com/mstaack "mstaack (1 commits)")

---

Tags

driverphpphpredispredisredisredis-servertimeseries

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/palicao-php-redis-time-series/health.svg)

```
[![Health](https://phpackages.com/badges/palicao-php-redis-time-series/health.svg)](https://phpackages.com/packages/palicao-php-redis-time-series)
```

###  Alternatives

[iazaran/smart-cache

Smart Cache is a caching optimization package designed to enhance the way your Laravel application handles data caching. It intelligently manages large data sets by compressing, chunking, or applying other optimization strategies to keep your application performant and efficient.

21114.2k](/packages/iazaran-smart-cache)[ichhabrecht/intcache

Turn uncachable page objects into cacheable links

193.9k](/packages/ichhabrecht-intcache)

PHPackages © 2026

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