All Projects → palicao → phpRedisTimeSeries

palicao / phpRedisTimeSeries

Licence: MIT license
📈 Use Redis Time Series in PHP!

Programming Languages

PHP
23972 projects - #3 most used programming language
Dockerfile
14818 projects

Projects that are alternatives of or similar to phpRedisTimeSeries

phpRebloom
🎛️ Use RedisBloom in PHP!
Stars: ✭ 20 (-13.04%)
Mutual labels:  redis-server, driver, predis
Phpfastcache
A high-performance backend cache system. It is intended for use in speeding up dynamic web applications by alleviating database load. Well implemented, it can drops the database load to almost nothing, yielding faster page load times for users, better resource utilization. It is simple yet powerful.
Stars: ✭ 2,171 (+9339.13%)
Mutual labels:  driver, predis
redis-developer.github.io
The Home of Redis Developers
Stars: ✭ 28 (+21.74%)
Mutual labels:  redis-server
vboxpower
VirtualBox Power Driver for MAAS
Stars: ✭ 107 (+365.22%)
Mutual labels:  driver
KMAC
Some usefull info when reverse engineering Kernel Mode Anti-Cheat
Stars: ✭ 31 (+34.78%)
Mutual labels:  driver
crystal-sqlite3
SQLite3 bindings for Crystal
Stars: ✭ 118 (+413.04%)
Mutual labels:  driver
Paperino
E-Paper display library for the Particle & Arduino family.
Stars: ✭ 35 (+52.17%)
Mutual labels:  driver
ant-arduino
An implementation of a ANT driver for Arduino, Mbed and ESP-IDF
Stars: ✭ 69 (+200%)
Mutual labels:  driver
mlx90632-library
MLX90632 library for the Melexis 90632 Infra Red temperature sensor.
Stars: ✭ 34 (+47.83%)
Mutual labels:  driver
readis
Lightweight web frontend in PHP for reading data, stats and config from multiple redis servers.
Stars: ✭ 38 (+65.22%)
Mutual labels:  redis-server
linux nvidia jetson
Allied Vision CSI-2 camera driver for NVIDIA Jetson Systems. Currently supporting Nano, TX2, AGX Xavier, and Xavier NX. Support for TX2 NX coming soon.
Stars: ✭ 68 (+195.65%)
Mutual labels:  driver
embedded-ccs811-rs
Platform agnostic Rust driver for the CCS811 ultra-low power digital gas sensor for monitoring indoor air quality
Stars: ✭ 12 (-47.83%)
Mutual labels:  driver
iotdb-client-go
Apache IoTDB Client for Go
Stars: ✭ 24 (+4.35%)
Mutual labels:  timeseries
timecorr
Estimate dynamic high-order correlations in multivariate timeseries data
Stars: ✭ 30 (+30.43%)
Mutual labels:  timeseries
hwidspoofer
HardwareID Spoofer using kernelmode
Stars: ✭ 68 (+195.65%)
Mutual labels:  driver
cdrs-tokio
High-level async Cassandra client written in 100% Rust.
Stars: ✭ 54 (+134.78%)
Mutual labels:  driver
hanbo-db
hanboDB is a high available,low latency memory database system
Stars: ✭ 29 (+26.09%)
Mutual labels:  redis-server
soxy-driver
A docker networking driver that transparently tunnels docker containers TCP traffic through a proxy
Stars: ✭ 25 (+8.7%)
Mutual labels:  driver
rust-radio-sx127x
Rust driver for the Semtech SX127x series of Sub-GHz LoRa/ISM radio transceivers
Stars: ✭ 21 (-8.7%)
Mutual labels:  driver
nativeble
A fully-fledged cross-platform BLE library for desktop.
Stars: ✭ 15 (-34.78%)
Mutual labels:  driver

phpRedisTimeSeries

Use Redis Time Series in PHP!

Maintainability Test Coverage Build Status Latest Stable Version PHP version GitHub

Getting up and running

Install

composer require palicao/php-redis-time-series

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

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

TimeSeries methods

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 https://oss.redislabs.com/redistimeseries/commands/#tscreate.

alter

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

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

See https://oss.redislabs.com/redistimeseries/commands/#tsalter.

add

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

Adds a sample.

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

See https://oss.redislabs.com/redistimeseries/commands/#tsadd.

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

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 https://oss.redislabs.com/redistimeseries/commands/#tsmadd.

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 https://oss.redislabs.com/redistimeseries/commands/#tsincrbytsdecrby.

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 https://oss.redislabs.com/redistimeseries/commands/#tscreaterule.

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

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

Deletes an existing aggregation rule.

See https://oss.redislabs.com/redistimeseries/commands/#tsdeleterule.

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 https://oss.redislabs.com/redistimeseries/commands/#tsrange.

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 Samples.

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

See https://oss.redislabs.com/redistimeseries/commands/#tsmrange.

getLastSample

TimeSeries::getLastSample(string $key): Sample

Gets the last sample for a key.

See https://oss.redislabs.com/redistimeseries/commands/#tsget.

getLastSamples

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

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

See https://oss.redislabs.com/redistimeseries/commands/#tsmget.

info

TimeSeries::info(string $key): Metadata

Gets useful metadata for a given key.

See https://oss.redislabs.com/redistimeseries/commands/#tsinfo.

getKeysByFilter

getKeysByFilter(Filter $filter): string[]

Retrieves the list of keys matching a given $filter.

See https://oss.redislabs.com/redistimeseries/commands/#tsqueryindex.

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

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

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

Thanks Mrkisha for the precious contributions.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].