Forum: NGINX md5 as memcached_key

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Geoff G. (Guest)
on 2009-01-26 19:43
 Hello,

 Does anyone know if nginx can calculate the md5 of a $request_uri
string?  I'd like to set the $memcached_key as the md5 of the
request_uri when passing requests for cached content to my memcached
instance.

 In concept the directive might look like this;

  location /testing {
  set $memcached_key $md5($request_uri);
  memcached_pass localhost:11211;
  }

Thanks!
Dave C. (Guest)
on 2009-01-26 23:43
(Received via mailing list)
md5 is not guaranteed to be unique, that is to say, two seperate
inputs can generate the same hash, so you would need to use extra
logic in your application if you wanted to guard against this remote
possibility. I'm guessing the problem you are trying to solve is the
memcache key has a limitation that is shorter than the possible
request_uri ?

Cheers

Dave
Geoff G. (Guest)
on 2009-01-27 00:47
Dave C. wrote:
> md5 is not guaranteed to be unique, that is to say, two seperate
> inputs can generate the same hash, so you would need to use extra
> logic in your application if you wanted to guard against this remote
> possibility. I'm guessing the problem you are trying to solve is the
> memcache key has a limitation that is shorter than the possible
> request_uri ?
>
> Cheers
>
> Dave

Thanks Dave,

 The problem is that memcached will not allow certain characters in the
key name - so I thought it might be simpler to just store the md5 of the
actual request_uri.

Thanks,

Geoff
Sergio Bruder (Guest)
on 2009-01-27 01:35
(Received via mailing list)
Em 26/01/2009, às 20:47, Geoff Geoff escreveu:

>> Dave
>
> Thanks Dave,
>
> The problem is that memcached will not allow certain characters in the
> key name - so I thought it might be simpler to just store the md5 of
> the
> actual request_uri.
>
> Thanks,
> Geoff

There are the theoretical chance of colision, yes, but you probably
can use
it anyway without a practical chance of colision.


Sergio Devojno Bruder
removed_email_address@domain.invalid
Haxent Consultoria
http://haxent.com.br/
41 3362-1460
41 9933-8764
Merlin (Guest)
on 2009-01-27 06:12
(Received via mailing list)
I agree that since this is not a cryptographic application, the fact
that
md5 has some collisions is less relevent, maybe even irrelevent unless
you
have a very large set of URIs you need to pull from memcached uniquely.

Due to the way nginx configuration and modules work, I am not sure that
it
is viable to have $md5(SOMETHING) return md5.  A more likely (and
probably
relatively easy to implement) solution might be something like this:

location /testing {
   set_md5 $memcached_key $request_uri;
   memcached_pass localhost:11211;
}

Perhaps I'll take a shot at it later on in the week :).
Xavier G. (Guest)
on 2009-02-03 17:22
(Received via mailing list)
Hello,

Less efficient for sure but  you could use perl_set  $memcached and a
simple perl script returning the md5 for a request_uri.

xav



Le 26 janv. 09 à 18:43, Geoff Geoff a écrit :
This topic is locked and can not be replied to.