Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

redis-cli and value from a file

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)
like image 933
vartec Avatar asked Nov 06 '13 16:11

vartec


People also ask

How fetch data from Redis?

During fetching the records from database,first check whether the key present(primary key i.e id) in redis,if "yes" get data directly from redis,otherwise hit the database for data. Suppose database tables are posts,comments.

How do I access Redis from command line?

To start Redis client, open the terminal and type the command redis-cli. This will connect to your local server and now you can run any command.

How do I access Redis config file?

The Redis configuration file is located at installdir/redis/etc/redis. conf.


1 Answers

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.

like image 91
deltheil Avatar answered Sep 18 '22 12:09

deltheil