Frantisek Fuka
2013-01-03 21:42:06 UTC
Hello,
I need to use Redis on my Linux machine from my script (in fact it's Lua
script, but I don't have access to LuaSocket library or any other custom
library, just to plain standard io.open and io.popen commands). It would be
easiest to just execute "redis-cli set xxx yyy" and read the command output
but the problem is my data is binary and contains all possible byte values
(including possibly newlines, quotes etc.) so I have to operate in raw mode.
That's no problem. I construct a command sequence like this, for example
(just an example, in reality the values are long binary strings):
**3*
*$3*
*SET*
*$5*
*mykey*
*$5*
*hello*
**2*
*$3*
*GET*
*$5*
*mykey*
I put all of this in com.txt file and then I exec this:
*cat com.txt | redis-cli --pipe --raw -s /tmp/redis_socket*
And grab the output. This ALMOST works, the commands get executed.
But I have no idea how I can get the result of these commands in my file to
be processed afterwards. I only get the following output:
All data transferred. Waiting for the last reply...
Last reply received from server.
errors: 0, replies: 2
How do I get the actual result of my commands, or at least the result of
the last command (the expected string "hello")?
I found another possible way, using netcat, which works like this:
*cat com.txt | nc -q 1 -U /tmp/redis_socket*
This returns:
*+OK*
*$5*
*hello*
Which is exactly what I want! Great! However, there is one second pause
which is a problem for me because I need to execute many Redis commands in
quick succession. And I cannot put them all into one long file because the
commands are generated based on the results of the previous commands. And
without pause, the socket is closed before I get the result back.
So I did one final modification, I forked the whole command when calling it:
*cat com.txt | nc -q 1 -U /tmp/redis_socket > result.txt &*
(Note the "&" at the end)
Now it SEEMS to me that this works perfectly and does exactly what I need.
But I'd like to know if this is indeed the simplest solution and won't lead
to any troubles when called like this 100 times a second. Have I missed
something?
I need to use Redis on my Linux machine from my script (in fact it's Lua
script, but I don't have access to LuaSocket library or any other custom
library, just to plain standard io.open and io.popen commands). It would be
easiest to just execute "redis-cli set xxx yyy" and read the command output
but the problem is my data is binary and contains all possible byte values
(including possibly newlines, quotes etc.) so I have to operate in raw mode.
That's no problem. I construct a command sequence like this, for example
(just an example, in reality the values are long binary strings):
**3*
*$3*
*SET*
*$5*
*mykey*
*$5*
*hello*
**2*
*$3*
*GET*
*$5*
*mykey*
I put all of this in com.txt file and then I exec this:
*cat com.txt | redis-cli --pipe --raw -s /tmp/redis_socket*
And grab the output. This ALMOST works, the commands get executed.
But I have no idea how I can get the result of these commands in my file to
be processed afterwards. I only get the following output:
All data transferred. Waiting for the last reply...
Last reply received from server.
errors: 0, replies: 2
How do I get the actual result of my commands, or at least the result of
the last command (the expected string "hello")?
I found another possible way, using netcat, which works like this:
*cat com.txt | nc -q 1 -U /tmp/redis_socket*
This returns:
*+OK*
*$5*
*hello*
Which is exactly what I want! Great! However, there is one second pause
which is a problem for me because I need to execute many Redis commands in
quick succession. And I cannot put them all into one long file because the
commands are generated based on the results of the previous commands. And
without pause, the socket is closed before I get the result back.
So I did one final modification, I forked the whole command when calling it:
*cat com.txt | nc -q 1 -U /tmp/redis_socket > result.txt &*
(Note the "&" at the end)
Now it SEEMS to me that this works perfectly and does exactly what I need.
But I'd like to know if this is indeed the simplest solution and won't lead
to any troubles when called like this 100 times a second. Have I missed
something?
--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To view this discussion on the web visit https://groups.google.com/d/msg/redis-db/-/Fl6IhUbAybsJ.
To post to this group, send email to redis-db-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to redis-db+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/redis-db?hl=en.
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To view this discussion on the web visit https://groups.google.com/d/msg/redis-db/-/Fl6IhUbAybsJ.
To post to this group, send email to redis-db-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to redis-db+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/redis-db?hl=en.