同志们,朋友们,抛弃phpredis扩展吧,使用nginx直接查redis……真的假的自己看看吧,春哥的模块哦

https://github.com/agentzh/redis2-nginx-module.git

wget 'http://nginx.org/download/nginx-1.2.7.tar.gz'
    tar -xzvf nginx-1.2.7.tar.gz
    cd nginx-1.2.7/

    # Here we assume you would install you nginx under /opt/nginx/.
    ./configure --prefix=/opt/nginx \
                --add-module=/path/to/redis2-nginx-module

    make -j2
    make install
location /foo {
        set $value 'first';
        redis2_query set one $value;
        redis2_pass 127.0.0.1:6379;
    }

    # GET /get?key=some_key
    location /get {
        set_unescape_uri $key $arg_key;  # this requires ngx_set_misc
        redis2_query get $key;
        redis2_pass foo.com:6379;
    }

    # GET /set?key=one&val=first%20value
    location /set {
        set_unescape_uri $key $arg_key;  # this requires ngx_set_misc
        set_unescape_uri $val $arg_val;  # this requires ngx_set_misc
        redis2_query set $key $val;
        redis2_pass foo.com:6379;
    }

    # multiple pipelined queries
    location /foo {
        set $value 'first';
        redis2_query set one $value;
        redis2_query get one;
        redis2_query set one two;
        redis2_query get one;
        redis2_pass 127.0.0.1:6379;
    }

    location /bar {
        # $ is not special here...
        redis2_literal_raw_query '*1\r\n$4\r\nping\r\n';
        redis2_pass 127.0.0.1:6379;
    }

    location /bar {
        # variables can be used below and $ is special
        redis2_raw_query 'get one\r\n';
        redis2_pass 127.0.0.1:6379;
    }

    # GET /baz?get%20foo%0d%0a
    location /baz {
        set_unescape_uri $query $query_string; # this requires the ngx_set_misc module
        redis2_raw_query $query;
        redis2_pass 127.0.0.1:6379;
    }

    location /init {
        redis2_query del key1;
        redis2_query lpush key1 C;
        redis2_query lpush key1 B;
        redis2_query lpush key1 A;
        redis2_pass 127.0.0.1:6379;
    }

    location /get {
        redis2_query lrange key1 0 -1;
        redis2_pass 127.0.0.1:6379;
    }
    location /pipelined {
        redis2_query set hello world;
        redis2_query get hello;

        redis2_pass 127.0.0.1:$TEST_NGINX_REDIS_PORT;
    }


分享到: 更多

这篇日志的 QR 二维码为:

十一月 26th, 2013

Posted In: 网络技术

发表评论

电子邮件地址不会被公开。 必填项已用*标注

无觅相关文章插件,快速提升流量