13

Is it possible to easily set specific value from a file using interactive redis-cli?

I'd like to achieve same result as with following Python snippet:

with open("some.jpg") as f:
    image_binary = f.read()

rd.hset("some_key", "image_binary", image_binary)
4

1 回答 1

26

Is it possible to easily set specific value from a file using interactive redis-cli?

Since -x reads the last argument from STDIN, what about:

redis-cli -x HSET some_key image_binary <some.jpg

You can then easily retrieve the file as follow:

redis-cli --raw HGET some_key image_binary > img.jpg

Note that there is an extra \n character at the end.

于 2013-11-06T22:10:50.190 回答