envato/flip — pull request #4 by eadz (2014-04-01 00:54:22+00:00)
Title: Only call to redis once per request

Currently for each request, the following redis calls are made: [1]

After this PR, one redis call is made per request:

```
1396312996.685677 [0 127.0.0.1:53540] "get" "flip-cache"
```

The flip statues are stored in a JSON encoded hash:
```
1396312989.549759 [0 127.0.0.1:53540] "set" "flip-cache" "{\"disable_search-global-enabled\":\"false\",\"disable_search-ip-percentage\":\"\",\"disable_search-deterministic_percentage-percentage\":\"1\",\"purchase_flow_modal-username-allowed_values\":\"bob\"}"
```

[1]

```redis
1396313257.415755 [0 127.0.0.1:53753] "hget" "flip--external_event_queue-global" "enabled"
1396313257.417761 [0 127.0.0.1:53753] "hget" "flip--external_event_queue-host" "allowed_hosts"
1396313257.419527 [0 127.0.0.1:53753] "hget" "flip--external_event_queue-ip" "percentage"
1396313257.512994 [0 127.0.0.1:53753] "hget" "flip--fancy_video_upload-global" "enabled"
1396313257.514869 [0 127.0.0.1:53753] "hget" "flip--fancy_video_upload-username" "allowed_values"
1396313257.516510 [0 127.0.0.1:53753] "hget" "flip--fancy_video_upload-role" "allowed_values"
1396313257.518205 [0 127.0.0.1:53753] "hget" "flip--fancy_video_upload-host" "allowed_hosts"
1396313257.519892 [0 127.0.0.1:53753] "hget" "flip--fancy_video_upload-deterministic_percentage" "percentage"
1396313257.521495 [0 127.0.0.1:53753] "hget" "flip--fancy_video_upload-ip" "percentage"
1396313257.689774 [0 127.0.0.1:53753] "hget" "flip--purchase_flow_modal-global" "enabled"
1396313257.691431 [0 127.0.0.1:53753] "hget" "flip--purchase_flow_modal-username" "allowed_values"
1396313257.693042 [0 127.0.0.1:53753] "hget" "flip--purchase_flow_modal-role" "allowed_values"
1396313257.694681 [0 127.0.0.1:53753] "hget" "flip--purchase_flow_modal-host" "allowed_hosts"
1396313257.696282 [0 127.0.0.1:53753] "hget" "flip--purchase_flow_modal-deterministic_percentage" "percentage"
1396313257.697838 [0 127.0.0.1:53753] "hget" "flip--purchase_flow_modal-ip" "percentage"
1396313257.699774 [0 127.0.0.1:53753] "hget" "flip--shopping_cart-global" "enabled"
1396313257.702436 [0 127.0.0.1:53753] "hget" "flip--shopping_cart-username" "allowed_values"
1396313257.705043 [0 127.0.0.1:53753] "hget" "flip--shopping_cart-role" "allowed_values"
1396313257.707553 [0 127.0.0.1:53753] "hget" "flip--shopping_cart-host" "allowed_hosts"
1396313257.710152 [0 127.0.0.1:53753] "hget" "flip--shopping_cart-deterministic_percentage" "percentage"
1396313257.713195 [0 127.0.0.1:53753] "hget" "flip--shopping_cart-ip" "percentage"
1396313257.786063 [0 127.0.0.1:53753] "hget" "flip--deferred_content-global" "enabled"
1396313257.787883 [0 127.0.0.1:53753] "hget" "flip--deferred_content-host" "allowed_hosts"
1396313257.789636 [0 127.0.0.1:53753] "hget" "flip--deferred_content-ip" "percentage"
1396313258.522892 [0 127.0.0.1:53753] "hget" "flip--proxy_images-global" "enabled"
1396313258.525281 [0 127.0.0.1:53753] "hget" "flip--proxy_images-username" "allowed_values"
1396313258.527634 [0 127.0.0.1:53753] "hget" "flip--proxy_images-role" "allowed_values"
1396313258.530044 [0 127.0.0.1:53753] "hget" "flip--proxy_images-host" "allowed_hosts"
1396313258.721618 [0 127.0.0.1:53759] "hget" "flip--proxy_images-deterministic_percentage" "percentage"
1396313258.724033 [0 127.0.0.1:53759] "hget" "flip--proxy_images-ip" "percentage"
1396313258.743094 [0 127.0.0.1:53759] "hget" "flip--more_similar_items-global" "enabled"
1396313258.745278 [0 127.0.0.1:53759] "hget" "flip--more_similar_items-username" "allowed_values"
1396313258.747320 [0 127.0.0.1:53759] "hget" "flip--more_similar_items-role" "allowed_values"
1396313258.749541 [0 127.0.0.1:53759] "hget" "flip--more_similar_items-host" "allowed_hosts"
1396313258.751775 [0 127.0.0.1:53759] "hget" "flip--more_similar_items-deterministic_percentage" "percentage"
1396313258.753856 [0 127.0.0.1:53759] "hget" "flip--more_similar_items-ip" "percentage"
1396313259.469608 [0 127.0.0.1:53759] "hget" "flip--hover_video_previews-global" "enabled"
1396313259.471820 [0 127.0.0.1:53759] "hget" "flip--hover_video_previews-username" "allowed_values"
1396313259.473759 [0 127.0.0.1:53759] "hget" "flip--hover_video_previews-role" "allowed_values"
1396313259.475775 [0 127.0.0.1:53759] "hget" "flip--hover_video_previews-host" "allowed_hosts"
1396313259.477813 [0 127.0.0.1:53759] "hget" "flip--hover_video_previews-deterministic_percentage" "percentage"
1396313259.479818 [0 127.0.0.1:53759] "hget" "flip--hover_video_previews-ip" "percentage"
1396313259.519914 [0 127.0.0.1:53759] "hget" "flip--business_model_clarification_enabled-global" "enabled"
1396313259.523739 [0 127.0.0.1:53759] "hget" "flip--business_model_clarification_enabled-global" "enabled"
1396313259.776238 [0 127.0.0.1:53759] "hget" "flip--author_handbook-global" "enabled"
1396313259.778790 [0 127.0.0.1:53759] "hget" "flip--author_handbook-username" "allowed_values"
1396313259.781381 [0 127.0.0.1:53759] "hget" "flip--author_handbook-role" "allowed_values"
1396313259.783903 [0 127.0.0.1:53759] "hget" "flip--author_handbook-host" "allowed_hosts"
1396313259.786110 [0 127.0.0.1:53759] "hget" "flip--author_handbook-deterministic_percentage" "percentage"
1396313259.788454 [0 127.0.0.1:53759] "hget" "flip--author_handbook-ip" "percentage"
1396313262.076090 [0 127.0.0.1:53759] "hget" "flip--external_event_queue-global" "enabled"
1396313262.078131 [0 127.0.0.1:53759] "hget" "flip--external_event_queue-host" "allowed_hosts"
1396313262.080000 [0 127.0.0.1:53759] "hget" "flip--external_event_queue-ip" "percentage"
1396313262.087190 [0 127.0.0.1:53759] "hget" "flip--fancy_video_upload-global" "enabled"
1396313262.088852 [0 127.0.0.1:53759] "hget" "flip--fancy_video_upload-username" "allowed_values"
1396313262.090536 [0 127.0.0.1:53759] "hget" "flip--fancy_video_upload-role" "allowed_values"
1396313262.092131 [0 127.0.0.1:53759] "hget" "flip--fancy_video_upload-host" "allowed_hosts"
1396313262.093840 [0 127.0.0.1:53759] "hget" "flip--fancy_video_upload-deterministic_percentage" "percentage"
1396313262.095550 [0 127.0.0.1:53759] "hget" "flip--fancy_video_upload-ip" "percentage"
1396313262.097271 [0 127.0.0.1:53759] "hget" "flip--purchase_flow_modal-global" "enabled"
1396313262.098903 [0 127.0.0.1:53759] "hget" "flip--purchase_flow_modal-username" "allowed_values"
1396313262.100637 [0 127.0.0.1:53759] "hget" "flip--purchase_flow_modal-role" "allowed_values"
1396313262.102225 [0 127.0.0.1:53759] "hget" "flip--purchase_flow_modal-host" "allowed_hosts"
1396313262.103822 [0 127.0.0.1:53759] "hget" "flip--purchase_flow_modal-deterministic_percentage" "percentage"
1396313262.105377 [0 127.0.0.1:53759] "hget" "flip--purchase_flow_modal-ip" "percentage"
1396313262.107213 [0 127.0.0.1:53759] "hget" "flip--shopping_cart-global" "enabled"
1396313262.108872 [0 127.0.0.1:53759] "hget" "flip--shopping_cart-username" "allowed_values"
1396313262.110802 [0 127.0.0.1:53759] "hget" "flip--shopping_cart-role" "allowed_values"
1396313262.112654 [0 127.0.0.1:53759] "hget" "flip--shopping_cart-host" "allowed_hosts"
1396313262.114571 [0 127.0.0.1:53759] "hget" "flip--shopping_cart-deterministic_percentage" "percentage"
1396313262.116141 [0 127.0.0.1:53759] "hget" "flip--shopping_cart-ip" "percentage"
```

What about specs?

Well it turns out that the flip gem's specs are no where near passing. There are specs for files that don't exist, and no specs to cover this functionality. As we are moving away from flip I have tested this manually (lol). If not having specs is a blocker, how did this gem get into the marketplace in the first place? And it would probably be a rewrite to make it all spec-covered. This is a stopgap to deal with this issue:

The number of 'redis timeout errors' occurring on production

![screen shot 2014-04-01 at 11 53 35 am](https://cloud.githubusercontent.com/assets/11939/2574671/16df58bc-b938-11e3-879f-da02915d61cc.png)