Skip to content

Handle integer replies, implement a connect timeout and dynamic config in VCL #2

Merged
merged 6 commits into from May 31, 2012

2 participants

@noahwilliamsson

Hi,

Please consider pulling the following patches (details available in the commit messages):
Noah Williamsson (6):
Handle REDIS_REPLY_INTEGER in vmod_call() and return it as a string
Initialize config (host, port) once per VCL instead of once every call
Implement a connect timeout for connecting to Redis, defaulting to 200ms
Allow the Redis server and timeout to be set in VCL via redis.init_redis()
Provide a commented out example of redis.init_redis() in examples/example.vcl
Fix typo in examples/example.vcl (redis.call -> redis.send)

Tested on 32- and 64-bit Linux aswell as Mac OS X with Varnish 3.0.2.

noahwilliamsson added some commits May 31, 2012
@noahwilliamsson noahwilliamsson Handle REDIS_REPLY_INTEGER in vmod_call() and return it as a string
Signed-off-by: Noah Williamsson <noah.williamsson@gmail.com>
3300bff
@noahwilliamsson noahwilliamsson Initialize config (host, port) once per VCL instead of once every call
Because the VCC specifies PRIV_CALL for vmod_send() and vmod_call(), the
vmod_priv argument is NULL for every call to these functions. This causes
the config struct to be re-allocated for every call.

This patch changes PRIV_CALL to PRIV_VCL, making the vmod_priv argument shared
between all calls to the module's functions within a given instance of a VCL.

The allocation of the config struct is also moved from redis_common() to
init_function().

Signed-off-by: Noah Williamsson <noah.williamsson@gmail.com>
f2c2ff0
@noahwilliamsson noahwilliamsson Implement a connect timeout for connecting to Redis, defaulting to 200ms
Use redisConnectWithTimeout() instead of redisConnect() to prevent
hanging for minutes when the host is down (i.e, not responding).

The default timeout is set to 200ms via REDIS_TIMEOUT_MS in vmod_redis.c.

Signed-off-by: Noah Williamsson <noah.williamsson@gmail.com>
caa623e
@noahwilliamsson noahwilliamsson Allow the Redis server and timeout to be set in VCL via redis.init_re…
…dis()

By default libvmod-redis attempts to connect to the Redis server
at 127.0.0.1, port 6379 with a connect timeout of 200 ms.

This patch allows the Redis hostname, port and timeout to be configured
via VCL using redis.init_redis(hostname, port, timeout_ms);

VCL example:
  import redis;
  sub vcl_init {
    redis.init_redis("localhost", 6379, 200);
  }

Signed-off-by: Noah Williamsson <noah.williamsson@gmail.com>
3b34657
@noahwilliamsson noahwilliamsson Provide a commented out example of redis.init_redis() in examples/exa…
…mple.vcl

Signed-off-by: Noah Williamsson <noah.williamsson@gmail.com>
68ce997
@noahwilliamsson noahwilliamsson Fix typo in examples/example.vcl (redis.call -> redis.send)
Signed-off-by: Noah Williamsson <noah.williamsson@gmail.com>
01d14b8
@andreacampi
ZephirWorks member

Awesome, thanks!

@andreacampi andreacampi merged commit 4397675 into zephirworks:master May 31, 2012
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.