arthurnn / memcached

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

Return of "exist" method #158

Closed mosuke5 closed 8 years ago

mosuke5 commented 9 years ago

Hi! I have a question about "exist" method. Why is this function's return exception not ture/false?

For example, in branching processing juding from whether key exists or not, we must use exception.

cache = Memcached.new("localhost:11211")
begin
    cache.exist("my_key")
    key_exist = true
rescue Memcached::NotFound => e
    key_exist = false
end

if key_exist?
    ...
else
    ...
end

But, I think we should write following way.

cache = Memcached.new("localhost:11211")
if cache.exist("my_key")?
   ...
else
   ...
end
anna64000 commented 8 years ago

thanks

arthurnn commented 8 years ago

Feel free to open a PR, and I will take a look

arthurnn commented 8 years ago

Hi, on the new version this will now return true/false .

thanks for reporting

mosuke5 commented 8 years ago

thank you! and i'm sorry that i don't open PR for this issue...