arthurnn / memcached

A Ruby interface to the libmemcached C client
Academic Free License v3.0
432 stars 125 forks source link

Passing a float ttl value results in undefined method `tv_sec' #24

Closed betamatt closed 14 years ago

betamatt commented 14 years ago

Float ttl values result from using Time math to produce a ttl value representing a fixed point in time. Sometimes this is necessary when two related keys, generated at different times, should expire at the same time. It's unlikely that anyone would ever intend to pass a float so converting it to an int seems to preserve the user's intention without requiring a lot of guard logic in the calling application.

I can understand if the reaction is to preserve 1:1 mapping between the ruby and C lib as strictly as possible but I've prepared a patch anyway. Perhaps there's a better approach than checking directly for Float-yness but I wasn't sure if it was safe to blindly call #to_i. http://github.com/Viximo/memcached/commit/6a7d473018fe13084376c180474452b880a38160

evan commented 14 years ago

I appreciate the intent, but I strongly prefer avoiding additional method dispatches in any of the runtime operations...the memcached client tends to be in the critical path of most users' systems. Not sure if there is a compromise here. :-(