# Retrieving memcache value for further processing

**URL:** <https://www.ruby-forum.com/t/retrieving-memcache-value-for-further-processing/182971>\
**Category:** NGINX\
**Created:** [February 5, 2010, 11:58am UTC](https://www.ruby-forum.com/t/retrieving-memcache-value-for-further-processing/182971 "2010-02-05T11:58:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mflive](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e99b99/32.png) [@mflive](https://www.ruby-forum.com/u/mflive)\
**Post date:** [February 5, 2010, 11:58am UTC](https://www.ruby-forum.com/t/retrieving-memcache-value-for-further-processing/182971/1 "2010-02-05T11:58:35Z")

</div>

Hello list,

I need some advice on how to solve my use-case. I have a memcache  
backend with  
some keys and values. Every HTTP request carries a cookie with a SHA1  
hash as  
value, this cookie value is also a key in memcache.

I already can retrieve the value and send it as a HTTP response using  
the  
following configuration:

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

```

key

```
    memc_pass 127.0.0.1:11211;
  }

```

The question is, how to actually retrieve the value in the configuration  
for  
further processing. For instance, i would like to put the value in the  
header  
before i proxy it upstream.

I have tried reading the $memc\_value but it seems it does not contain  
the  
result and that it is only being used for setting or appending a key. If  
i  
proxy\_pass to $memc\_value after executing memc\_pass, it throws an error,  
telling me the $memc\_value was still empty.

In the end i need to perform several small operations on some conditions  
with  
several memcache values before proxying the entire request upstream. Can  
i  
even do this with the configuration and memc addon? Or would i need some  
inline perl script to do so?

I use the latest 0.7 Nginx and 0.6 Memc addon.

Regards,

Markus J. - Technisch Architect - Buyways BV  
[http://www.linkedin.com/in/markus17](http://www.linkedin.com/in/markus17)  
050-8536620 / 06-50258350

---

<div class="post-metadata">

**Author:** ![mflive](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e99b99/32.png) [@mflive](https://www.ruby-forum.com/u/mflive)\
**Post date:** [February 5, 2010, 1:44pm UTC](https://www.ruby-forum.com/t/retrieving-memcache-value-for-further-processing/182971/2 "2010-02-05T13:44:33Z")

</div>

Thanks Mauro!

This looks rather promising! I will try this.

Cheers

> you should check the eval module:  
> [http://www.grid.net.ru/nginx/eval.en.html](http://www.grid.net.ru/nginx/eval.en.html)

By the way, why don’t i receive a copy of my own e-mail? I have the  
following  
setting enabled.  
Ordinarily, you will get a copy of every message you post to the list.  
If you  
don’t want to receive this copy, set this option to No.

Markus J. - Technisch Architect - Buyways BV  
[http://www.linkedin.com/in/markus17](http://www.linkedin.com/in/markus17)  
050-8536620 / 06-50258350

---

<div class="post-metadata">

**Author:** ![mflive](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e99b99/32.png) [@mflive](https://www.ruby-forum.com/u/mflive)\
**Post date:** [February 5, 2010, 1:15pm UTC](https://www.ruby-forum.com/t/retrieving-memcache-value-for-further-processing/182971/3 "2010-02-05T13:15:52Z")

</div>

you should check the eval module:  
[http://www.grid.net.ru/nginx/eval.en.html](http://www.grid.net.ru/nginx/eval.en.html)
