How to set html files into memcache

agentzh agentzh at gmail.com
Sun Jun 17 14:11:25 UTC 2012


Hello!

On Sun, Jun 17, 2012 at 8:06 PM, amodpandey <nginx-forum at nginx.us> wrote:
> I have a memcache cluster (multiple
> nodes). So I defined an
>
> upstream memcached_pass_stream {
>  server node1:11211;
>  server node2:11211;
>  server node3:11211;
>  server node4:11211;
> }
>
> And I pass it
> memcached_pass $scheme://memcached_pass_stream/;
>
> I am using memcached cluster (AWS ElastiCache)
>
> Q1 I hope this is the right way to integrate with multiple nodes.
>

No, unless all your memcached nodes are read-only and contain exactly
the same data copy.

> Q2 If yes, what logic nginx follows to pick the nodes? I should use
> similar logic to set data else there might be many misses.
>

By default, round-robin is used to pick up nodes. You can do key
modulo hashing by means of the set_hashed_upstream directive provided
by the ngx_set_misc module:

    http://wiki.nginx.org/HttpSetMiscModule#set_hashed_upstream

Alternatively, you can just use some Lua code to calculate the backend
upstream name in arbitrary way that you like for each individual
request. See ngx_lua for details. And here's an example that
determines a backend for proxy_pass on-the-fly by querying a redis
backend via a little Lua code:

    http://openresty.org/#DynamicRoutingBasedOnRedis

The basic idea is essentially the same.

Regards,
-agentzh



More information about the nginx mailing list