Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP



dobe opened this Issue · 2 comments

2 participants

Bernd Dorn Yichun Zhang
Bernd Dorn

hi agentzh

do you know if it is possible to somehow use the standard CRC32_HASH algorithm for multiple memcached servers
my example location:

location ~ "/memcached_get/(.+)" {
    set $memc_key $1;
    set $memc_cmd get;
    set_hashed_upstream $backend er $1;
    echo $backend;
    #memc_pass $backend;

with such a config the server hashing is not compatible with our other services accessing memcached

thanks in advance, bernd

Bernd Dorn

for now i've added a patch to set-misc-module, would be better to somehow implement another directive

what do you think?

diff --git a/src/ngx_http_set_hashed_upstream.c b/src/ngx_http_set_hashed_upstream.c
index a924502..7051cf6 100755
--- a/src/ngx_http_set_hashed_upstream.c
+++ b/src/ngx_http_set_hashed_upstream.c
@@ -78,7 +78,8 @@ ngx_http_set_misc_set_hashed_upstream(ngx_http_request_t *r,

     dd("key: \"%.*s\"", key->len, key->data);

-    hash = ngx_hash_key_lc(key->data, key->len);
+    hash = (ngx_crc32_short(key->data, key->len) >> 16) & 0x7fff;
+    hash = hash ? hash : 1;

     index = ngx_http_set_misc_apply_distribution(r->connection->log, hash, ul,
Yichun Zhang
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.