QNimate

  • CoursesVideos
  • WP PremiumPlugins
  • DemosLab
  • Home
  • QIdea
  • QTrack
Home Carbon Ads Storing Binary Data in Redis

Storing Binary Data in Redis

Redis is a in-memory key-value storage system. Primary Memory storage size tends to be much smaller than hard disk storage size. So its never a good idea to populate primary memory with binary data/files as you will soon run out of memory and cause redis/other applications unexpected shutdowns.

But still if you want to store binary data in redis then follow these instructions:

  • You can store the binary file in filesystem and then store the path to the file in redis. This is the recommended method if you want to manage binary data with redis.
  • You can also store binary files/data directly inside redis. Redis keys and values don’t have to be text strings. They can be binary. So a png/exe/pdf etc file can be a key or value in redis. The limitation is that the maximum allowed size of a single key or value is 512MB. You can create binary keys or values the same way you create string keys and values but with binary data. Redis internally represents all keys and values as binary blob(binary sequence of data).When you have large size keys/values your redis instance becomes slower(i.e., comparison during lookup is slower, hashing is slower etc) therefore not recommended to store binary data. You will need to use programming language APIs to store binary data in redis as command line redis client takes only readable characters as input. If you still want to use redis command line client then make sure you first encode binary data using Base64 encoding standard and then give the encoded data to redis command line client for input.

This is an php example to store a image file inside redis value.

$client = new Predis\Client();
$client->set('profile_picture', file_get_contents("profile.png"));//value is binary
$client->set(file_get_contents("profile.png"), 'profile_picture');//key is binary
Sep 19, 2014Narayan Prusty
Web Components Complete GuideRedis Permanent Storage
Comments: 1
  1. Dexter
    5 years ago

    abe chutiyta hai kya…. title dekh or post dekh… binary data save karna bata na redis mai

    ReplyCancel

Leave a Reply Cancel reply

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

Narayan Prusty

I am a software engineer specialising in Blockchain, DevOps and Go/JavaScript. This is my personal blog where I write about things that I learn and feel interesting to share.

7 years ago 1 Comment Databases
Share this
0
GooglePlus
0
Facebook
0
Twitter
0
Linkedin
Related Articles
  • Redis Permanent Storage
  • Overview Of Redis Architecture
  • Storing Binary Files in Redis
  • Storing Image in Redis
  • Database Design For Storing Chat Messages
Our Sponsor
My Books

2014 - 2015 © QNimate
All tutorials MIT license