-
Notifications
You must be signed in to change notification settings - Fork 354
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
simplified command execution - the Connection is an implementation de… #2
Conversation
…tail Usage example: Redis redis("tcp://127.0.0.1:6379"); char const* clientName = "Hugo"; redis.command("CLIENT SETNAME %s",clientName);
Usage example: |
Maybe it would be a good idea to provide a cmake switch CPP_11 and enable the simplified version only, if that switch is not set. (Of course, additionally the cxx flag should be controlled by that switch). |
Hi @arnead First of all, thanks a lot for your pull request! Yes, you're right. User defined I have to say this interface is NOT user-friendly, and I was thinking about having a simplified version. Your proposal, i.e. A better interface might be something like: I'll try to implement it this week. If you have any problem or other proposal, please feel free to let me know. Thanks again for your work! |
Hi sewenew,
the example you mention does not need to be invoked as „command“ by the end user – for set the user can call the function
bool set(const StringView &key,
const StringView &val,
const std::chrono::milliseconds &ttl = std::chrono::milliseconds(0),
UpdateType type = UpdateType::ALWAYS)
which exists for both RedisCluster and Redis.
Additionally, my proposal simply adds an overload of the command function to Redis.
This could be done for RedisCluster as well, provided that there is a non-empty set of commands which can be executed as formatted string.
And I don’t understand, why it is easier to get the „set“ semantic of a command if it is wrapped in a function.
redis.command(function,StringView,StringView) can be any redis command that accepts two strings, for instance CONFIG SET parameter value.
So, whenever a command needs to be handled differently by a redis cluster client, you can solve that by adding an explicit function interface to both Redis and RedisCluster (which you already have for set).
Kind Regards,
Arne Adams
Von: sewenew <[email protected]>
Gesendet: Donnerstag, 13. Dezember 2018 17:32
An: sewenew/redis-plus-plus <[email protected]>
Cc: arnead <[email protected]>; Mention <[email protected]>
Betreff: Re: [sewenew/redis-plus-plus] simplified command execution - the Connection is an implementation de… (#2)
Hi @arnead <https://github.com/arnead> First of all, thanks a lot for your pull request!
Yes, you're right. Connection is implementation detail, and it should NOT be exposed to end users. I design this complicate interface for the following reason:
User defined Cmd function, e.g. void set_udf(const StringView &key, const StringView &val), can be reused for both Redis::command and RedisCluster::command. So that we can call redis.command(set_udf, "key", "val") and redis_cluster.command(set_udf, "key", "val").
I have to say this interface is NOT user-friendly, and I was thinking about having a simplified version.
Your proposal, i.e. redis.command("set %s %s", "key", "val"), is good for Redis. However, it CANNOT work with RedisCluster very well. For RedisCluster, we need to automatically get the key of the command, so that we can send it to the right node. With your proposal, we CANNOT easily achieve the goal.
A better interface might be something like: redis.command("set", "key", "val") and redis_cluster.command("set", "key", "val"). For RedisCluster, we can easily get the key of the command, i.e. the second parameter of RedisCluster::command (by now, RedisCluster doesn't support command without a key as parameter).
I'll try to implement it this week. If you have any problem or other proposal, please feel free to let me know. Thanks again for your work!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#2 (comment)> , or mute the thread <https://github.com/notifications/unsubscribe-auth/AkGuP6AovRIA1ZKIbsW22t5BCyEU7RtTks5u4oDkgaJpZM4ZRHqu> . <https://github.com/notifications/beacon/AkGuP786MMV0vJPR0oq1-osuwDX43p7Cks5u4oDkgaJpZM4ZRHqu.gif>
|
Hi Arne, I'm not a native speaker, and my previous comment might be confusing for you. Sorry for that, and I'll try to explain in detail.
Yes, you don't need to invoke
When we send command to Redis Cluster, we need to do the following work:
If we overload
In my previous comment, I gave an example of a simpler interface, and didn't provide the prototype, and it might make you confused. The prototype should be something like: That's all. I hope this comment explains my thoughts, and won't confuse you any more :) Regards |
Hi Arne, I add an easy-to-use command interface for
Please check the latest code for detail, and hope this interface can be helpful :) Regards |
For most of time, it's redundant to call
Sorry for the inconvenience. |
Hi Sewenew, I think your idea to return the result directly (as an Optional where applicable) is great. |
Hi Arne, I finally figured out why you got those error messages: you installed some old version of hiredis :). Old version hiredis defines I've fixed the problem to make the code compatible with old version hiredis, and now the minimum version requirement for hiredis is v0.12.1. Please try the latest code. Thanks a lot for finding the bug!
First of all, you don't need to call
With CLIENT SETNAME connection-name, the command is, in fact, CLIENT, NOT CLIENT SETNAME. SETNAME is just one of the two arguments of this command, or you can take SETNAME as a subcommand. So I prefer to pass CLIENT and SETNAME separately. Also, if we support Regards |
Hi Arne, I've implemented the generic command interface, and you can use it like this:
Hope you like it. Regards |
…tail
Usage example:
Redis redis("tcp://127.0.0.1:6379");
char const* clientName = "Hugo";
redis.command("CLIENT SETNAME %s",clientName);