Browse Source

Merge pull request #7127 from jamienoss/issue13224-memcached-add-delete

HPCC-13224 Memcached - add Delete(<key>) function

Reviewed-By: Gavin Halliday <gavin.halliday@lexisnexis.com>
Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 10 years ago
parent
commit
f57c5be2be

+ 1 - 0
plugins/memcached/lib_memcached.ecllib

@@ -37,4 +37,5 @@ export memcached := SERVICE : plugin('memcached'), namespace('MemCachedPlugin')
   BOOLEAN Exists(CONST VARSTRING key, CONST VARSTRING options, CONST VARSTRING partitionKey = '') : cpp,action,context,entrypoint='MExists';
   CONST VARSTRING KeyType(CONST VARSTRING key, CONST VARSTRING options, CONST VARSTRING partitionKey = '') : cpp,action,context,entrypoint='MKeyType'; //NOTE: calls get
   Clear(CONST VARSTRING options) : cpp,action,context,entrypoint='MClear';
+  Delete(CONST VARSTRING key, CONST VARSTRING options, CONST VARSTRING partionKey = '') : cpp,action,context,entrypoint='MDelete';
 END;

+ 16 - 1
plugins/memcached/memcachedplugin.cpp

@@ -97,6 +97,7 @@ public :
 
     void clear(ICodeContext * ctx, unsigned when);
     bool exists(ICodeContext * ctx, const char * key, const char * partitionKey);
+    void deleteKey(ICodeContext * ctx, const char * key, const char * partitionKey);
     eclDataType getKeyType(const char * key, const char * partitionKey);
 
     bool isSameConnection(const char * _options) const;
@@ -486,7 +487,16 @@ bool MemCachedPlugin::MCached::exists(ICodeContext * ctx, const char * key, cons
     }
 #endif
 }
-
+void MemCachedPlugin::MCached::deleteKey(ICodeContext * ctx, const char * key, const char * partitionKey)
+{
+    memcached_return_t rc;
+    size_t partitionKeyLength = strlen(partitionKey);
+    if (partitionKeyLength)
+        rc = memcached_delete_by_key(connection, partitionKey, partitionKeyLength, key, strlen(key), (time_t)0);
+    else
+        rc = memcached_delete(connection, key, strlen(key), (time_t)0);
+    assertOnError(rc, "'Delete' request failed - ");
+}
 MemCachedPlugin::eclDataType MemCachedPlugin::MCached::getKeyType(const char * key, const char * partitionKey)
 {
     size_t returnValueLength;
@@ -571,6 +581,11 @@ ECL_MEMCACHED_API const char * ECL_MEMCACHED_CALL MKeyType(ICodeContext * ctx, c
     const char * keyType = enumToStr(serverPool->getKeyType(key, partitionKey));
     return keyType;
 }
+ECL_MEMCACHED_API void ECL_MEMCACHED_CALL MDelete(ICodeContext * ctx, const char * key, const char * options, const char * partitionKey)
+{
+    OwnedMCached serverPool = MemCachedPlugin::createConnection(ctx, options);
+    serverPool->deleteKey(ctx, key, partitionKey);
+}
 //-----------------------------------SET------------------------------------------
 //NOTE: These were all overloaded by 'value' type, however; this caused problems since ecl implicitly casts and doesn't type check.
 ECL_MEMCACHED_API void ECL_MEMCACHED_CALL MSet(ICodeContext * ctx, const char * key, size32_t valueLength, const char * value, const char * options, const char * partitionKey, unsigned __int64 expire /* = 0 (ECL default)*/)

+ 1 - 0
plugins/memcached/memcachedplugin.hpp

@@ -65,6 +65,7 @@ namespace MemCachedPlugin {
     ECL_MEMCACHED_API bool             ECL_MEMCACHED_CALL MExists (ICodeContext * _ctx, const char * key, const char * options, const char * partitionKey);
     ECL_MEMCACHED_API const char *     ECL_MEMCACHED_CALL MKeyType(ICodeContext * _ctx, const char * key, const char * options, const char * partitionKey);
     ECL_MEMCACHED_API void             ECL_MEMCACHED_CALL MClear  (ICodeContext * _ctx, const char * options);
+    ECL_MEMCACHED_API void             ECL_MEMCACHED_CALL MDelete (ICodeContext * _ctx, const char * key, const char * options, const char * partitionKey);
 }//close namespace
 }
 #endif

+ 12 - 0
testing/regress/ecl/key/memcachedtest.xml

@@ -46,3 +46,15 @@
 <Dataset name='Result 16'>
  <Row><Result_16>false</Result_16></Row>
 </Dataset>
+<Dataset name='Result 17'>
+ <Row><Result_17>true</Result_17></Row>
+</Dataset>
+<Dataset name='Result 18'>
+ <Row><Result_18>false</Result_18></Row>
+</Dataset>
+<Dataset name='Result 19'>
+ <Row><Result_19>true</Result_19></Row>
+</Dataset>
+<Dataset name='Result 20'>
+ <Row><Result_20>false</Result_20></Row>
+</Dataset>

+ 12 - 0
testing/regress/ecl/memcachedtest.ecl

@@ -90,3 +90,15 @@ SEQUENTIAL(
     Std.System.Debug.Sleep(2 * 1000);
     memcached.Exists('testExpire', servers);
     );
+
+SEQUENTIAL(
+    memcached.SetString('testDelete', 'foobar', servers);
+    memcached.Exists('testDelete', servers);
+    memcached.Delete('testDelete', servers);
+    memcached.Exists('testDelete', servers);
+
+    memcached.SetString('testDelete', 'foobar', servers, 'hashWithThis');
+    memcached.Exists('testDelete', servers, 'hashWithThis');
+    memcached.Delete('testDelete', servers, 'hashWithThis');
+    memcached.Exists('testDelete', servers, 'hashWithThis');
+    );