Does anyone know how to check if a key exists using Membase Client (Enyim)? I dont want to pull the entire object from the cache, just check if its in there.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Unfortunately there is no “exists” operation in memcached, but there are some hacks you can do:
client.Store(StoreMode.Add, keyToCheck, null, new Date(2000, 1, 1));Add fails if the item already exists, and will return false in this case.client.Append(keyToCheck, new ArraySegment<byte>(new byte[0]))This will returntrueif the key exists, but its value will not change.client.Cas(StoreMode.Set, keyToCheck, null, UInt64.MaxValue)This will also fail if the item exists.Please keep in mind that all three operations will create an item if the key does not exist, so you need to clean up after them.
Also, if multiple threads are checking for the same item, then it’s possible that one thread will treat another threads temp item as the real one.