Store WebM file in Redis (NodeJS)

1.3k Views Asked by At

I'm searching a solution to store a WebM file into Redis.

Let's explain the situation:

  • The NodeJS server receive a WebM file from a client, and save it into server file system.
  • Then it have to save this file in redis, because I don't want to manage redis and file system too. In this way I can delete the video just with redis command.

I think to read file with fs.readFile() and then save it into a Buffer, but I don't know witch encode format to use, and I don't know how to refer this process to give back the WebM video to a client when it make a request.

Is this a good way to proceed? Any suggestion?

PS: I use formidable to upload file.


EDIT: I found a way to proceed, but theres another problem:

var file = fs.readFileSync("./video.webm");
client.set("video1", file1, function(){
    client.get("video1", function(err, data) {
        var buffer = new Buffer(data, 'binary');
        // file ≠ buffer
    });
});

Is this an encode problem? Like unicode/UTF8/ASCII? Maybe node and redis use different encode?

2

There are 2 best solutions below

3
On

I don't know much about NodeJS and WebM files.

Redis stores C char type on 8 bit String, so it should be binary friendly. Check the js code and configuration to ensure your js redis client sends / receives data as bytearray and not as UTF-8 string, probably there is a bad conversion in JS of data.

0
On

Solution found! The problem became when you create the client object.

Usually this is what is done

 var client = redis.createClient(); 

And return_buffers param will be set as false.

In this way

var client = redis.createClient(6379, '127.0.0.1', {
    return_buffers: true,
    auth_pass: null
});

everything gone right! ;)

this is the issue page they help me