1

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?

RikyTres
  • 676
  • 9
  • 31
  • Is storing video files on redis a good idea? I don't think so. You can look at GridFS on MongoDB instead. – Munim Dec 11 '13 at 12:04
  • I'm doing this for a university project and they say that is better in this way... I think too that is not a good idea. – RikyTres Dec 11 '13 at 17:34

2 Answers2

1

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

RikyTres
  • 676
  • 9
  • 31
0

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.

zenbeni
  • 7,019
  • 3
  • 29
  • 60
  • I read in [another question](http://stackoverflow.com/questions/8963372/how-to-save-and-retrieve-string-with-accents-in-redis) that `the Redis server itself stores all data as a binary objects`, and then I don't know what to think about now... It's all binary or all string? :O – RikyTres Dec 13 '13 at 10:03
  • Seems you are right. It is in fact C-like 8 bits String, so it is binary safe. It musts then be a problem with your js client that has to be configured to send bytearray and not UTF-8 string: js should be the problem. I'll add an edit. – zenbeni Dec 13 '13 at 10:18
  • client does not send nothing... Server read a file from file-system with fs.readFileSync() and this return a Buffer with binary content. Console.log of that buffer return something like this: `` and then I think that this Buffer object is in binary decode and not in utf-8 decode... right? – RikyTres Dec 13 '13 at 16:12