michael-grunder
Repos
40
Followers
115
Following
32

Redis is an in-memory database that persists on disk. The data model is key-value, but many different kind of values are supported: Strings, Lists, Sets, Sorted Sets, Hashes, Streams, HyperLogLogs, Bitmaps.

C
56936
15375

A PHP extension for Redis

C
9465
2033

Minimalistic C client for Redis >= 1.2

C
5426
1624

Events

pull request opened
BLPOP with a float timeout

See #2157

Created at 1 day ago

BLPOP with a float timeout

See #2157

Created at 1 day ago

BLPOP with a float timeout

See #2157

Created at 2 days ago
closed issue
redisReply->elements = 0,but it actually has content

Bug report

When I use RPUSH to sent data and BLPOP to receive data,encountered an errorre ,disReply->elements = 0,but it actually has content

Steps to Reproduce

I want to use the hiredis to transfer data between two node.In the receiver,I open up multiple threads to block waiting to receive data from the sender.I made sure the data was successfully filled in at the sender,but there is an error in the receiver. error:

reply->elements = 0, ERROR
//sender
redisContext *_coordinatorCtxconn  = redisConnect("receiverIP",6379);
char cmd[]="hello world\n";
redisReply* reply;
int cmdoffset = strlen(cmd);
redisAppendCommand(_coordinatorCtx, "RPUSH dr_request_t %b", cmd, cmdoffset);
redisGetReply(_coordinatorCtx, (void**)&reply); // send "dr_request_t"
freeReplyObject(reply);
//receiver
redisContext *_coordinatorCtxconn  = redisConnect("127.0.0.1",6379);
while (true) {
        if (COORDINATOR_DEBUG) cout << "waiting for requests ..." << endl;
        /* Redis command: BLPOP (LISTNAME1) [LISTNAME2 ...] TIMEOUT */
        reply = (redisReply*)redisCommand(rContext, "BLPOP dr_request_t 100"); // [0]
        if (reply->type == REDIS_REPLY_NIL) {
            cerr << __func__ << " empty queue " << endl;
            freeReplyObject(reply);
            continue;
        } else if (reply->type == REDIS_REPLY_ERROR) {
            cerr << __func__ << " ERROR happens " << endl;
            freeReplyObject(reply);
            continue;
        } else {
            if((int)reply->elements == 0) {
                cerr << __func__ << " reply->elements = 0, ERROR " << endl;
                continue;
            }
            
            //
            //
        }
}

I tried to write a test program ,where the data could be successfully received.

type:2
elements:2
element[0]:dr_request_t
element[1]:hello world
element[1]:hello world
//test code
#include <stdio.h>
#include <hiredis/hiredis.h>
#include <string>
#include <string.h>
int main(){

    redisReply *reply;
    redisContext *conn  = redisConnect("127.0.0.1",6379);
    if(conn != NULL && conn->err)
    {
        printf("connection error: %s\n",conn->errstr);
        return 0;
    }      
    reply =(redisReply*)redisCommand(conn, "BLPOP dr_request_t 100");
    printf("type:%d\n",(int)reply->type);
    printf("elements:%d\n",(int)reply->elements);
    for(int i=0;i<reply->elements;++i){
        printf("element[%d]:%s\n",i,reply->element[i]->str);
    }
    printf("element[%d]:%s\n",1,reply->element[1]->str);
    freeReplyObject(reply);
    redisFree(conn);
    return 0;
}

I want to know how this problem should be solved

Created at 3 days ago
issue comment
redisReply->elements = 0,but it actually has content

I'm going to close this issue, since it's unlikely a bug in hiredis but if you can provide an example to replicate the problem I'm happy to help track it down.

Created at 3 days ago
closed issue
How to select different db execution "keys *"
redisReply * _reply;

 _reply = (redisReply*)redisCommand(_redisCxt, "select 1");
 _reply = (redisReply*)redisCommand(_redisCxt, "keys *");

if (_reply->type == REDIS_REPLY_ARRAY){
        for (int i = 0; i < _reply->elements; ++i){
             _reply->element[i]->str;
        }
}

question: The keys I got are all in the database db0. I need to select different db to get all keys at the same time, what do I need to do. thanks!

Created at 3 days ago
issue comment
How to select different db execution "keys *"

As @bjosv says, you should check to make sure the SELECT command is not returning an error.

#include <hiredis/hiredis.h>
#include <string.h>
#include <assert.h>

#include <hiredis/hiredis.h>
#include <string.h>
#include <assert.h>

int main(void) {
    redisContext *_redisCtx;
    redisReply *_reply;

    _redisCtx = (redisContext*)redisConnect("localhost", 6379);
    assert(_redisCtx != NULL && _redisCtx->err == 0);

    _reply = (redisReply*)redisCommand(_redisCtx, "select 1");
    assert(_reply != NULL && _reply->type == REDIS_REPLY_STATUS &&
           _reply->len == 2 && !strcmp(_reply->str, "OK"));
    freeReplyObject(_reply);

    _reply = (redisReply*)redisCommand(_redisCtx, "keys *");
    assert(_reply != NULL && _reply->type == REDIS_REPLY_ARRAY);

    for (size_t i = 0; i < _reply->elements; i++) {
        assert(_reply->element[i]->type == REDIS_REPLY_STRING);
        printf("KEY[%zu]: %s\n", i, _reply->element[i]->str);
    }

    freeReplyObject(_reply);
    redisFree(_redisCtx);
}

Cluster mode being enabled is the most likely issue (as it disables database numbers) but you can also verify this via redis-cli.

I'm going to close this issue since it's unlikely to be a bug in hiredis but I'm happy to help you figure it out. 😄

Created at 3 days ago

Update tests, fix BZPOPMIN/MAX logic

See #2157

Created at 3 days ago

Add a test when running against Redis >= 6.0.0

See #2157

Created at 3 days ago
create branch
michael-grunder create branch issue.2157-float-brpop-timeout
Created at 3 days ago
closed issue
Unable to load dynamic library 'redis.so' on php8.1 with igbinary

Expected behaviour

Actual behaviour

I'm seeing this behaviour on

  • OS: Mac OS 12.1
  • Redis:6.2.6
  • PHP:8.1
  • phpredis:5.3.5

$ pecl install igbinary // 3.2.7 $ pecl install zstd $ pecl install redis

Steps to reproduce, backtrace or example script

[13-Jan-2022 20:34:31] NOTICE: PHP message: PHP Warning: PHP Startup: Unable to load dynamic library 'redis.so' (tried: /usr/local/lib/php/pecl/20210902/redis.so (dlopen(/usr/local/lib/php/pecl/20210902/redis.so, 0x0009): symbol not found in flat namespace '_igbinary_serialize'), /usr/local/lib/php/pecl/20210902/redis.so.so (dlopen(/usr/local/lib/php/pecl/20210902/redis.so.so, 0x0009): tried: '/usr/local/lib/php/pecl/20210902/redis.so.so' (no such file), '/usr/local/lib/redis.so.so' (no such file), '/usr/lib/redis.so.so' (no such file))) in Unknown on line 0

Created at 3 days ago
issue comment
Unable to load dynamic library 'redis.so' on php8.1 with igbinary

Going to close this issue as answered

Created at 3 days ago
issue comment
Allow float timeout values for brpop command

We should update the command to take a float, but in the meantime you can always use rawCommand

$r = new Redis; 
$r->connect('localhost', 6379);

$r->rpush('foo', 'a','b','c');
while ($res = $r->rawCommand('brpop', 'foo', .1)) {
    print_r($res);
}
Created at 3 days ago
closed issue
hScan return value doesn't always match php method signature

Expected behaviour

As per hScan documentation, the function should always return an array.

Actual behaviour

It is observed that the method returns false when the hash doesn't have anything set, which makes sense.

Further to this, phpstan and probably the php compiler recognises that this hScan function should only return an array. The method return signature in the extension is probably defining this.

I'm seeing this behaviour on

  • OS: Linux
  • Redis: 6.0.10
  • PHP: 7.4.14
  • phpredis: 5.3.2

Steps to reproduce, backtrace or example script

<?php

$r = new \Redis();
$r->connect('127.0.0.1');
$r->setOption(Redis::OPT_SCAN, Redis::SCAN_RETRY);
$r->hSet('abc123', 'myfield', 'myvalue');

$it = null;

print 'Test #1:' . PHP_EOL;
var_dump($r->hScan('myfield', $it));

print PHP_EOL;

print 'Test #2:' . PHP_EOL;
var_dump($r->hScan('myfield2', $it));

$r->close();

OUTPUT:

Test #1:
array(0) {
}

Test #2:
bool(false)

I've checked

  • 👍 There is no similar issue from other users
  • 👍 Issue isn't fixed in develop branch

Final note

The fix for this can either be as per documentation or to fix the method signature to correctly state the returning of FALSE as an option. Either way works for me.

Created at 3 days ago
issue comment
hScan return value doesn't always match php method signature

Closing this in favor of #1921.

There's a draft PR #2015 to fix these, the issue is it likely requires a major version bump.

Created at 3 days ago

Implement CONFIG RESETSTAT

Rework the CONFIG command and add RESETSTAT variant.

Fixes #1673

Created at 3 days ago

What's failing

Created at 3 days ago

Implement CONFIG RESETSTAT

Rework the CONFIG command and add RESETSTAT variant.

Fixes #1673

Created at 3 days ago
create branch
michael-grunder create branch php8.2-deprecations
Created at 3 days ago
create branch
michael-grunder create branch issue.1673.resetstat
Created at 3 days ago
pull request opened
Make sure we set an error for key based scans

See #1661

Created at 4 days ago

Add PHPREDIS_GET_OBJECT and PHPREDIS_ZVAL_GET_OBJECT macros

Fix redis_cluster GET_CONTEXT usage

fix usage php_hash_fetch_ops with PHP 8

Change version_compare usage in tests

Merge branch 'nightly' into develop

Various small changes in cluster_library

Issue #1721

Sanity check for redis_sock->stream before closing.

Fix arginfo for Redis::zadd

Update Changelog.md

Remove duplicate definitions

Remove unused declarations

Update Changelog.md

Set redis_sock->stream to NULL to avoid use-after-free

Update session.save_path in RedisClusterTest::sessionTest

requirepass

Authenticate in redis_sock_server_open

Merge pull request #1731 from phpredis/server-open-auth

Server open auth

Fix documentation to show lPush and rPush are variadic. (#1737)

Addresses #1734

Refactor redis_sock_get_connection_pool

Make unit test authentication configurable (#1748)

Right now cloning the repo and running unit tests will all fail if the Redis/RedisCluster instances aren't configured with the password 'phpredis'.

This commit simply makes authentication during the tests optional via a command-line argument.

Created at 4 days ago
delete branch
michael-grunder delete branch unix-sock-timeout-example
Created at 4 days ago

Add an example with a unix socket and timeout

See: #1663

Created at 4 days ago
closed issue
Add example of how to connect to a unix socket with a timeout

NOTE: This might also be a regression fixed in dev-master

* Fix regression for conntecting to ports > 32767 [1f41da64] (Owen Smith)

Expected behaviour

- *port*: int, optional
+ *port*: int, optional. Set this to null/0 for unix socket paths starting with / if you need to pass other parameters

https://github.com/phpredis/phpredis#connect-open

Actual behaviour

Examples only exist with TCP. There's no explicit documentation of what port you should pass alongside a unix socket if you want to pass a timeout.

I'm seeing this behaviour on

  • OS: Linux
  • Redis: N/A
  • PHP: 7.2
  • phpredis: 5.1.0RC2 - I see that there's a fix added to Redis::CONNECT to convert negative ports to 0.

Steps to reproduce, backtrace or example script

I've checked

  • [x] There is no similar issue from other users
  • [x] Issue isn't fixed in develop branch (Documentation isn't clear on develop, but the bug may have been fixed)

What was the intent of https://github.com/phpredis/phpredis/commit/a080b73f ?

Would the following change make more sense instead?

-     if (address[0] == '/' && redis_sock->port < 1) {
+     if (address[0] == '/' || redis_sock->port < 1) {
Created at 4 days ago
pull request closed
Add an example with a unix socket and timeout

Fixes: #1663

Created at 4 days ago
pull request opened
Add an example with a unix socket and timeout

Fixes: #1663

Created at 4 days ago
create branch
michael-grunder create branch unix-sock-timeout-example
Created at 4 days ago
closed issue
Github release information

Expected behaviour

Release information provided for this project at https://api.github.com/repos/phpredis/phpredis/releases/latest, similar to https://api.github.com/repos/php-memcached-dev/php-memcached/releases/latest and https://api.github.com/repos/igbinary/igbinary/releases/latest.

For more info, refer to https://developer.github.com/v3/repos/releases/#get-the-latest-release

Actual behaviour

I get a Not Found error message.

I'm seeing this behaviour on

  • OS: n/a
  • Redis: n/a
  • PHP: n/a
  • phpredis: n/a

Steps to reproduce, backtrace or example script

See above.

I've checked

  • [x ] There is no similar issue from other users
  • [x ] Issue isn't fixed in develop branch
Created at 4 days ago
issue comment
Github release information

Closing as I made a release :smile: https://api.github.com/repos/phpredis/phpredis/releases/latest

Created at 4 days ago