Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Redis to serve URL map to nginx

I want to maintain a dynamic database in Redis with SEO-friendly URLs as keys and nasty querystring URLs as values. I want to call this directly from Nginx when the request comes in, get the nasty querystring URL and pass that along to Apache to serve content.

I have thought about just having a flat map file, but that would be pretty huge (200,000+ entries) and it would have to be updated often by a cron job or something... not very elegant.

My idea is something like this:

map $uri $new {
    # instead of this...
    # include /path/to/the/nginx_map.txt;
    # I want to do this...
    redis_magic_thing GET $uri;
}

I have been checking out the HttpRedis Module for Nginx but the examples are really sparse and it seems more geared towards serving up cached content. I have also checked out the Redis2 module, but that seems like overkill. I just need to do plain old GET commands.

Can I use the HttpRedis module to do this and hook right into Redis? If so, what would such a configuration look like?

Thanks in advance for your help.

like image 694
Greg Robbins Avatar asked Nov 13 '22 18:11

Greg Robbins


1 Answers

You are right about HttpRedis being more geared towards caching. You would be better served using the redis2 module. The commands you need to execute are better provided by the more general case that redis2 provides

like image 189
Lloyd Moore Avatar answered Dec 06 '22 02:12

Lloyd Moore