Is there any functionality in StackExchange.Redis that allows you to execute raw commands directly? Like I'd provide a string with the command, e.g. (hypothetical code below):
conn.Send("ZADD mysortedset 1 john");
I know there are methods available for just about every command including ZADD
, but that's not the point.
redis is fully thread safe; the expected usage is that a single multiplexer is reused between concurrent requests etc - very parallel.
StackExchange. Redis is a high performance general purpose redis client for . NET languages (C#, etc.). It is the logical successor to BookSleeve, and is the client developed-by (and used-by) Stack Exchange for busy sites like Stack Overflow.
The ConnectionMultiplexer is the main arbiter of the connection to Redis inside the CLR, your application should maintain a single instance of the ConnectionMultiplexer throughout its runtime. You can initialize the Multiplexer with either a connection string, or with a ConfigurationOptions object.
The introduction of "modules" made this a lot more relevant; this API now exists in Execute(...)
. See: http://blog.marcgravell.com/2017/04/stackexchangeredis-and-redis-40-modules.html
Previously:
Not currently, and I'd be dubious of the benefit. In particular, doing this wouldn't allow correct routing on sharded instances (twemproxy, redis-cluster, etc), wouldn't allow renamed command-map usage, and wouldn't allow binary keys / values to be used. It would also allow very risky and concept-breaking commands to be used inappropriately, such as select
, watch
/multi
/exec
, blocking-pops brpop
/blpop
/brpoplpush
- all of which would be catastrophic to the multiplexer (well, select
isn't a biggie, as it can just be configured such that Send
leaves the db undefined - the code for that already exists thanks to some similar examples). It would also expose dangerous commands that should never need to be used from a general library: debug segfault
, client pause
, etc - again, all very bad ideas.
But sure, in theory it could be done... but I would really want to see a compelling reason to offset the many problems above.
At the moment, the most exposed way to execute ad-hoc commands is via ScriptEvaluate
- it would involve writing Lua, of course.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With