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

[Question] What will happen if I subscribe fd in redisContext with EPOLLIN? #1277

Open
w1nda opened this issue Sep 10, 2024 · 1 comment
Open

Comments

@w1nda
Copy link

w1nda commented Sep 10, 2024

The code link:

redisFD fd;

Thanks for attention,
My understanding is that EPOLLIN means when the associated file(fd) is available for read it will notify subscriber.

If I subscribe fd in redisContext with EPOLLIN, when I will got notified?
Or, put it in another way, what the fd means in redisContext? can I communicate with redis server with that fd(socket?)?
Or, put it in another way, when the socket is not ready for read?

@michael-grunder
Copy link
Collaborator

On Linux (or Linux-like) systems, redisFD is just a plain integer file descriptor. The reason there is an abstraction is to handle Windows.

hiredis/hiredis.h

Lines 173 to 183 in e0f4820

#ifndef _WIN32
typedef int redisFD;
#define REDIS_INVALID_FD -1
#else
#ifdef _WIN64
typedef unsigned long long redisFD; /* SOCKET = 64-bit UINT_PTR */
#else
typedef unsigned long redisFD; /* SOCKET = 32-bit UINT_PTR */
#endif
#define REDIS_INVALID_FD ((redisFD)(~0)) /* INVALID_SOCKET */
#endif

You can use any of the common functions to operate against file descriptors. It's important to be careful if you manually poll/read/write to the fd while the redisContext owns it, but this is perfectly doable.

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