Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using info or config in a multi/exec #411

Closed
chrisskilton opened this issue Dec 14, 2016 · 5 comments
Closed

Using info or config in a multi/exec #411

chrisskilton opened this issue Dec 14, 2016 · 5 comments

Comments

@chrisskilton
Copy link

I have just migrated from node_redis. I had a check script that did the following:

redis.multi()
        .info()
        .config('get', 'maxmemory')
        .exec()
        .then(console.log) //works in node_redis, outputs [] in ioredis

Running the commands individually works (not using multi). Is this by design? I only used the multi in the first place to reduce a bit of nesting as I need to munge the results.

@luin
Copy link
Collaborator

luin commented Dec 15, 2016

It should return with the correct result:
image

Could you please provide a minimal reproducible example?

@chrisskilton
Copy link
Author

I had the code wrapped in redis.on('connect'). Here's a reproducible example.

script:

'use strict';

const Redis = require('ioredis');
const redis = new Redis();

redis.on('connect', () => {
    console.log('redis connected');
    redis.info().then(info => {
        console.log('redis.info response', info);
    });

    redis.config('get', 'maxmemory').then(maxMem => {
        console.log('redis.config response', maxMem);
    });

    redis.multi().info().config('get', 'maxmemory').exec().then(results => {
        console.log('redis.multi response', results);
    });
});
$ node check-scripts/test.js
redis connected
redis.info response # Server
redis_version:3.0.7
redis_git_sha1:00000000
redis_git_dirty:0

...

redis.config response [ 'maxmemory', '3145728000' ]
redis.multi response []

The multi does work outside the connect callback.

@luin
Copy link
Collaborator

luin commented Dec 15, 2016

Thank for the report! I just confirmed this is a bug due to a race condition. It happens when sending pipeline/transaction that includes info or config command on the "connect" event.

I'm going to fix this today. BTW, It's recommended to handle the "ready" event instead of the "connect" event, since the latter one is a low level event emitted by the "net" module directly.

@luin
Copy link
Collaborator

luin commented Dec 15, 2016

Fixed in v2.4.3. 🍻

@chrisskilton
Copy link
Author

closing this as it's fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants