# Nginx redis, select database not working?

**URL:** <https://www.ruby-forum.com/t/nginx-redis-select-database-not-working/207862>\
**Category:** NGINX\
**Created:** [June 4, 2011, 2:41pm UTC](https://www.ruby-forum.com/t/nginx-redis-select-database-not-working/207862 "2011-06-04T14:41:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [June 4, 2011, 2:41pm UTC](https://www.ruby-forum.com/t/nginx-redis-select-database-not-working/207862/1 "2011-06-04T14:41:08Z")

</div>

I’m having problem with redis module: [HTTP Redis | NGINX](http://wiki.nginx.org/HttpRedis)  
(version 0.32 downloaded from mirror at  
[GitHub - elcuervo/nginx\_http\_redis: Mirror from wiki.nginx.org](https://github.com/elcuervo/nginx_http_redis))

As I tried, variable $redis\_db is never used and result always comes  
from “default” - database 0.  
Am I missing something in my config?

my nginx.conf (part of):  
upstream { server 192.168.2.178:6379; keepalive 256 single;}

location /testredisselect0  
{  
default\_type text/html;  
set $redis\_key “$uri?dbid=notdef”;  
redis\_pass redisbackend;  
}

location /testredisselect1  
{  
default\_type text/html;  
set $redis\_db “1”;  
set $redis\_key “$uri?dbid=1”;  
redis\_pass redisbackend;  
}

curl “[http://localhost/testredisselect0](http://localhost/testredisselect0)”  
curl “[http://localhost/testredisselect1](http://localhost/testredisselect1)”

result in redis monitor:  
1307190385.099634 “select” “0”  
1307190385.099688 “get” “/testredisselect0?dbid=notdef”  
1307190387.739512 “select” “0”  
1307190387.739561 “get” “/testredisselect1?dbid=1”

As I can see, command always issues select 0, although it should run  
select 1 in second case.

Damir

Posted at Nginx Forum:

> **[Nginx redis, select database not working?](https://forum.nginx.org/read.php?2,203861,203861#msg-203861)**
>
> I'm having problem with redis module: http://wiki.nginx.org/HttpRedis (version 0.32 downloaded from mirror at https://github.com/elcuervo/nginx\_http\_redis) As I tried, variable $redis\_db is never used and result always comes from "default"...

---

<div class="post-metadata">

**Author:** ![logar.damir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/2acd7d/32.png) [@logar.damir](https://www.ruby-forum.com/u/logar.damir)\
**Post date:** [June 7, 2011, 8:45pm UTC](https://www.ruby-forum.com/t/nginx-redis-select-database-not-working/207862/2 "2011-06-07T20:45:48Z")

</div>

Did that rev actually compile and make without issue for you? I was  
using that module a while back and ended up commenting out the below  
line inorder for it to build successfully.

/\* static ngx\_str\_t ngx\_http\_redis\_db = ngx\_string(“redis\_db”); \*/

I wasn’t using different redis db’s at the time and didn’t look into it  
much. I bet pipelining with agentzh’s redis2 would work just fine. I  
saw your post over in the parser thread, did you give that a try yet?

Posted at Nginx Forum:

> **[Re: Nginx redis, select database not working?](https://forum.nginx.org/read.php?2,203861,204766#msg-204766)**
>
> I'm having problem with redis module: http://wiki.nginx.org/HttpRedis (version 0.32 downloaded from mirror at https://github.com/elcuervo/nginx\_http\_redis) As I tried, variable $redis\_db is never used and result always comes from "default"...

---

<div class="post-metadata">

**Author:** ![logar.damir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/2acd7d/32.png) [@logar.damir](https://www.ruby-forum.com/u/logar.damir)\
**Post date:** [June 7, 2011, 8:51pm UTC](https://www.ruby-forum.com/t/nginx-redis-select-database-not-working/207862/3 "2011-06-07T20:51:58Z")

</div>

Hi.

On Sat, Jun 04, 2011 at 08:40:20AM -0400, logar.damir wrote:

> I’m having problem with redis module: [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/HttpRedis)  
> (version 0.32 downloaded from mirror at  
> [GitHub - elcuervo/nginx\_http\_redis: Mirror from wiki.nginx.org · GitHub](https://github.com/elcuervo/nginx_http_redis))

I don’t know anything about this URL. Original sources available  
from [http://people.freebsd.org/~osa/](http://people.freebsd.org/~osa/)

> As I tried, variable $redis\_db is never used and result always comes  
> from “default” - database 0.  
> Am I missing something in my config?

[skipped]

> As I can see, command always issues select 0, although it should run  
> select 1 in second case.

Patch.

---

<div class="post-metadata">

**Author:** ![logar.damir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/2acd7d/32.png) [@logar.damir](https://www.ruby-forum.com/u/logar.damir)\
**Post date:** [June 8, 2011, 3:50am UTC](https://www.ruby-forum.com/t/nginx-redis-select-database-not-working/207862/4 "2011-06-08T03:50:27Z")

</div>

@gregr401 I applied the patch to original redis module, as provided  
by Sergey. It works great. Previous I used module from Git. Compiled OK.  
Regarding Redis2: I use it when advanced processing is required  
(pipeline, redis Lua script). When all I need is simple get with high  
frequency I prefer strict C module.

@Sergey. Used original download url now and applied your patch. Work’s  
great. Thanks again. Problem solved.

Result in redis monitor after patch applied.  
1307496425.913180 “get” “/testredisselect0?dbid=notdef”  
1307496426.063073 “select” “0”  
1307496426.063085 “get” “/testredisselect0?dbid=notdef”  
1307496428.237644 (db 1) “select” “1”  
1307496428.237657 (db 1) “get” “/testredisselect1?dbid=1”  
1307496428.985250 (db 1) “select” “1”  
1307496428.985262 (db 1) “get” “/testredisselect1?dbid=1”  
1307496429.165848 (db 1) “select” “1”

Posted at Nginx Forum:

> **[Re: Nginx redis, select database not working?](https://forum.nginx.org/read.php?2,203861,204859#msg-204859)**
>
> I'm having problem with redis module: http://wiki.nginx.org/HttpRedis (version 0.32 downloaded from mirror at https://github.com/elcuervo/nginx\_http\_redis) As I tried, variable $redis\_db is never used and result always comes from "default"...
