I am in the process of replacing a basic file serving API call which looks like this:
return Results.File("myfile.pdf", MediaTypeNames.Application.Pdf, enableRangeProcessing: true);
If I store "myfile.pdf" as a byte array (AKA string?) in Redis, how can I later serve the file in a similar as I currently am?
Does Redis have the ability to return a string as a stream, and if it does, do range requests on that stream work as expected? (only transferring the minimum bytes required to fulfil the range request)
2
Answers
Redis strings are binary. You can retrieve substrings with the GETRANGE command.
You can’t stream as such, but you can read the contents of the string in chunks using the
StringLength
andStringGetRange
methods in StackExchange.Redis.Wrapping this is a stream wouldn’t be a terribly difficult exercise. And, honestly, if you’re so inclined, wouldn’t be a terrible open-source project. 😉