On Sep 17, 10:57 am, Jak Sprats <
jakspr...@gmail.com> wrote:
> but syntactically its not a good fit, and changing existing commands
> is a nogo as there is code already built against them.
Agreed. The ZRANGE | HSET case is particularly tricky.
However, with regard to the 1to1/NtoN mapping thing, I think it would
be easy to find workarounds. For example, if COMMAND_1 returns 1
value, and COMMAND_2 needs two args, you could do
COMMAND_1 | COMMAND_2 arg1
where the second argument for COMMAND_2 will be filled with the output
of COMMAND_1. Or maybe even
COMMAND_1 | COMMAND_2 - arg2
where the first argument for COMMAND_2 will be filled with the output
of COMMAND_1.
Heck, you could even do printf, though I suspect it would be overkill.
Anyway, people do command piping and argument juggling all the time in
the Unix shell. Each command does one thing and one thing well, and
you combine commands to do what you want to do. The protocol just
needs to be consistent.
Redis already does a similar thing in one case: SORT...GET. Normally,
the result of SORT is a list, one result per line. This is "piped"
into MGET as arguments, so that the corresponding keys are returned
instead. One could generalize from this example, and implement some
sort of "duck typing", so that piping works if and only if the
commands on either side are compatible. Otherwise you'd get an error.
A similar item on my wishlist would be simple logical operators such
as AND/OR. This would make it super easy to make commands conditional
on the result of a boolean-returning command, such as EXISTS, all the
while maintaining atomicity and reducing round-trips. Some existing
commands such as SETNX is actually equivalent to EXISTS OR SET. One
could make a "reverse SETNX" by writing EXISTS AND SET. Similar things
can be done with other boolean-returning commands, such as SADD,
SISMEMBER, HEXISTS, etc. Again, the Unix shell provides this
capability, and it's amazing what one can do with simple logical
primitives such as AND/OR and piping without using anything as
convoluted as SQL.
Relying on a combination of primitives might also take the pressure
off the Redis developers to keep adding slightly different commands
that do slightly different things. You'd just tell the user to combine
existing commands, which is so much easier to do when you don't have
to rely on a delicate balance of WATCH/UNWATCH, MULTI/EXEC and so on.
Maybe I've been spoiled by the new redis-cli, which is probably why I
keep thinking of importing Unix shell features to Redis... But Redis
does look to me like an exemplary embodiment of Unix principles. Maybe
we could get something along these lines in Redis 3.x?