Setting memcache keys in eval block

Markus Jelsma markus at
Wed Feb 10 13:18:01 MSK 2010


Thanks for your reply. The manual indeed tells us to set it inside the block, 
which i am doing. However, the first result cannot be passed to the second 
eval block;

The following does not work; it sends the error message $memc_key variable is 
not set:

      eval $key
        # Check if we got the token, a 160bit SHA1 hash
        if ($cookie_token ~* "([A-Za-z0-9]{40})")
          # Attempt to retrieve the token from memcache
          set $memc_cmd 'get';
          set $memc_key $cookie_token;

          # Retrieve the token's value and store it in the local key variable
      eval $email
        set $memc_cmd 'get';
        set $memc_key $key;

      echo 'test';
      echo $email;

I really need two seperate gets. Nesting the  second eval in the first is also 
not allowed because then we have a duplicate memc_pass which it complains 

For the moment i `solved` this issue by adding a second location which the 
first eval proxies to, this does work but shows up as a second HTTP request in 
the logs; this feels a bit slow and i really would like to handle this subject 
within one location directive.

To summarize the problem; using a variable set by eval in a subsequent eval 
block does not work. 

Some advice is much appreciated :)


The eval module's handler runs before the ngx_rewrite module. So make
sure you always "set" variables inside the eval block. The "set"
directives outside the eval block does not work because they run after
the "eval" block and hence the memcached handler complete.

IIRC, this was mentioned in the ngx_eval module's documentation.

Markus Jelsma - Technisch Architect - Buyways BV
050-8536620 / 06-50258350

More information about the nginx mailing list