Visitar URL original
Implement `INCREX` (Redis 8.8.0) · Issue #2897 · phpredis/phpredis · GitHub
Skip to content

Implement INCREX (Redis 8.8.0) #2897

Description

@simonhammes

This is especially useful for rate limiters:

A common rate-limiting pattern requires atomically incrementing a counter and setting its expiration. With plain INCR and EXPIRE, this typically requires a Lua script to be atomic. INCREX requires a single native command.

Docs:

Activity

  1. simonhammes commented on Jul 23, 2026

    @simonhammes
    ContributorAuthor

    I'll try to implement this myself.

  2. michael-grunder commented on Jul 23, 2026

    @michael-grunder
    Member

    You're welcome to implement it. I already implemented it in the Relay P{HP extension so we'll want to keep the same prototyp

        public function increx(string $key, null|int|float $value = null, ?array $options = null): Redis|array|false;

    After way too many years working on Redis clients in PHP those option arrays are very useful for when the command inevitibly adds a new option.

    // INCREX foo
    $redis->increx('foo');
    
    // INCREX foo  BYINT 42
    $redis->increx('foo', 42); 
    
    // INCREX foo BYFLOAT 3.14
    $redis->increx("foo", 3.14); 

    And then the options can augment the command in a bunch of ways

    //INCREX foo BYINT 42 LBOUND -100
    $redis->increx('foo', 42, ['SATURATE', 'LBOUND' => -100]);
  3. simonhammes commented on Jul 30, 2026

    @simonhammes
    ContributorAuthor

    You're welcome to implement it. I already implemented it in the Relay P{HP extension so we'll want to keep the same prototyp

    That makes sense.

    public function increx(string $key, null|int|float $value = null, ?array $options = null): Redis|array|false;

    What is the rationale behind $value being null|int|float? Wouldn't int|float $value = 1 be more succinct and equally "correct"?

    After way too many years working on Redis clients in PHP those option arrays are very useful for when the command inevitibly adds a new option.

    👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions