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

the parameter 'px' of func 'set' does not work #1215

Closed
cocoonYh opened this issue Sep 23, 2019 · 7 comments
Closed

the parameter 'px' of func 'set' does not work #1215

cocoonYh opened this issue Sep 23, 2019 · 7 comments

Comments

@cocoonYh
Copy link

cocoonYh commented Sep 23, 2019

Version:
redis-py: 2.10.6, redis: 5.0.5

Platform:
python 2.7 on macOS

Description:
the parameter 'px' of func 'set' does not work sometimes, here is my code:

logger.info('interval: %s' % interval)
res = r.set(key, 1, nx=True, px=interval)
logger.info('pttl: %s' % r.pttl(api_name))

and here is my log. i got so many 'None'. help please!
redis.log

@andymccurdy
Copy link
Contributor

I don't have enough information to fully understand what's going on.

Is this log from a process that is multithreaded? There are chunks of successive "pttl" lines and chunks of successive "interval" lines. That would suggest that multiple processes or threads are writing to the same log which makes it difficult to follow what's going on.

If your process is multithreaded, how are you sharing the redis-py instance(s) between the threads?

Your code sample above references a variable named key when setting value and a variable named api_name when querying the TTL. Is that intended? If so, I don't understand what results you're hoping to see from this log.

You're running a version of redis-py that's more than 2 years old. We've made significant improvements to the library since then.

@cocoonYh
Copy link
Author

I run my project using this command:
celery -A tasks.celery worker -l info -E -c 100 -P gevent
and my code is:

def get_redis_client(host=REDIS_HOST, password=REDIS_AUTH, port=REDIS_PORT, db=None, **kwargs):
    return redis.Redis(host=host, password=password, port=port, db=db, **kwargs)

def could_be_called(api_name, interval):
    r = get_redis_client(db=ROLLBACK_DB)
    logger.info('interval: %s' % interval)
    res = r.set(api_name, 1, nx=True, px=interval)
    logger.info('pttl: %s' % r.pttl(api_name))
    return False if res is None else True

@cocoonYh
Copy link
Author

And the func could_be_called will be called by a celery task.

@cocoonYh
Copy link
Author

By the way, which version of redis-py would you suggest using in production environment?

@cocoonYh
Copy link
Author

cocoonYh commented Sep 24, 2019

And when i update the version of redis-py to 3.3.8, i got an error.
ref: celery/celery#5175

It seems to be an issue with redis.

@cocoonYh
Copy link
Author

I solve it by updating the version of redis-py to v3.3.8, it seems to be a problem with v.2.10.6

@andymccurdy
Copy link
Contributor

Great. Feel free to reopen if the issue comes back for some reason.

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