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

[FEATURE] Add support for Redis Functions #514

Closed
MattJustMatt opened this issue Sep 4, 2023 · 6 comments
Closed

[FEATURE] Add support for Redis Functions #514

MattJustMatt opened this issue Sep 4, 2023 · 6 comments

Comments

@MattJustMatt
Copy link

MattJustMatt commented Sep 4, 2023

Is your feature request related to a problem? Please describe.
We use Redis Functions to perform atomic R+W operations in a more ergonomic way than the evalsha API.

Describe the solution you'd like
The ability to use redis fcall in redis-plus-plus

Describe alternatives you've considered
Transactions, evalsha, and calling out to a separate component with Redis function support

Additional context
Thank you so much for making this library!

@MattJustMatt MattJustMatt changed the title [FEATURE] [FEATURE] Add support for Redis Functions Sep 4, 2023
@sewenew
Copy link
Owner

sewenew commented Sep 5, 2023

Thanks for your suggestion! I'll try to add built-in support for Redis Function.

B.T.W. Before that feature is ready, you can use the generic interface to send commands related to Redis Function:

auto r = Redis("redis://127.0.0.1");
auto lib = r.command<string>("FUNCTION", "LOAD", 
    "#!lua name=mylib\nredis.register_function('knockknock', function() return 'Who\\'s there?' end)");
auto res = r.command<string>("FCALL", "knockknock", 0);

Regards

@MattJustMatt
Copy link
Author

@sewenew thank you for looking at this! We tried the generic command interface, but there's a problem!

The command interface is treating the first argument to .command as the key. This is a problem in Redis Cluster configurations because our FCALL command calls are being routed to the wrong node/slot.

For example
Server::redis_cluster->command<std::string>("FCALL", "authorize_player_join", 1, to_std_string(tprint("p:%", filled_request->user_id)), g_game_context.server_id);

This command will (almost) always fail, because it's using "authorize_player_join" as the key, instead of the third argument. So, we always get sent to the same (incorrect) Redis host.

@sewenew
Copy link
Owner

sewenew commented Sep 12, 2023

You can use the RedisCluster::redis(const StringView &hash_tag, bool new_connection = true) to work around this problem. Check this issue and the doc for detail.

NOTE: In order to improve performance, you should set new_connection parameter to be false.

Regards

@ivantishchenko
Copy link

@sewenew

Thanks for your suggestion! I'll try to add built-in support for Redis Function.

Do you have any updates on this? 🙈

@sewenew
Copy link
Owner

sewenew commented Mar 17, 2024

@ivantishchenko Sorry, but there's no progress on this topic. Too busy these days, I'll try it when I'm available. I'll let you know when there's progress.

Regards

@sewenew
Copy link
Owner

sewenew commented Oct 2, 2024

#598 supports Redis function.

@sewenew sewenew closed this as completed Oct 2, 2024
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

3 participants