From 489bda54b334bf6712cb868446418ebf3bc6678a Mon Sep 17 00:00:00 2001 From: Date: Fri, 15 Feb 2008 12:33:41 +0530 Subject: [PATCH] Bug fix for memcached_cas() operator. --- ChangeLog | 1 + lib/memcached_response.c | 5 +++++ lib/memcached_storage.c | 4 ++-- tests/function.c | 13 +++++++++++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 35f91ed7..21fb30c6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,7 @@ * Added MEMCACHED_BAD_KEY_PROVIDED error for auto, set, and get operations. MEMCACHED_BEHAVIOR_VERIFY_KEY was added to enable this feature. * More error messages on command line tools. + * Fixed bugs in memcached_cas() operator. 0.15 Tue Jan 29 14:55:44 PST 2008 * More work on the C++ API. diff --git a/lib/memcached_response.c b/lib/memcached_response.c index 33dc0b1e..6f9e7c33 100644 --- a/lib/memcached_response.c +++ b/lib/memcached_response.c @@ -145,6 +145,11 @@ memcached_return memcached_response(memcached_server_st *ptr, memcached_io_reset(ptr); return MEMCACHED_PROTOCOL_ERROR; } + else if (buffer[1] == 'X') + { + memcached_io_reset(ptr); + return MEMCACHED_DATA_EXISTS; + } else { memcached_io_reset(ptr); diff --git a/lib/memcached_storage.c b/lib/memcached_storage.c index 443389e0..6d115913 100644 --- a/lib/memcached_storage.c +++ b/lib/memcached_storage.c @@ -206,7 +206,7 @@ memcached_return memcached_cas(memcached_st *ptr, memcached_return rc; rc= memcached_send(ptr, key, key_length, key, key_length, value, value_length, - expiration, flags, cas, APPEND_OP); + expiration, flags, cas, CAS_OP); return rc; } @@ -297,6 +297,6 @@ memcached_return memcached_cas_by_key(memcached_st *ptr, memcached_return rc; rc= memcached_send(ptr, key, key_length, key, key_length, value, value_length, - expiration, flags, cas, APPEND_OP); + expiration, flags, cas, CAS_OP); return rc; } diff --git a/tests/function.c b/tests/function.c index 7c61db78..2a17a9cc 100644 --- a/tests/function.c +++ b/tests/function.c @@ -332,6 +332,19 @@ uint8_t cas_test(memcached_st *memc) assert(strlen("we the people") == value_length); assert(rc == MEMCACHED_SUCCESS); + rc= memcached_cas(memc, key, key_length, + "change the value", strlen("change the value"), + 0, 0, memcached_result_cas(results)); + + assert(rc == MEMCACHED_SUCCESS); + + rc= memcached_cas(memc, key, key_length, + "change the value", strlen("change the value"), + 0, 0, 23); + + assert(rc == MEMCACHED_DATA_EXISTS); + + memcached_result_free(&results_obj); return 0; -- 2.30.2