Revision
14649
Author
rupa
Date
2009-08-27 11:07:36 -0500 (Thu, 27 Aug 2009)

Log Message

add support for expires and flags for inc/dec operators
expires based on first inc/dec operator, subsequent ones do not 
extend the lifetime of the object

Modified Paths

Diff

Modified: freeswitch/trunk/src/mod/applications/mod_memcache/mod_memcache.c (14648 => 14649)


--- freeswitch/trunk/src/mod/applications/mod_memcache/mod_memcache.c	2009-08-27 16:04:00 UTC (rev 14648)
+++ freeswitch/trunk/src/mod/applications/mod_memcache/mod_memcache.c	2009-08-27 16:07:36 UTC (rev 14649)
@@ -44,7 +44,7 @@
 static char *SYNTAX = "memcache <set|replace|add> <key> <value> [expiration [flags]]\n"
   "memcache <get|getflags> <key>\n"
   "memcache <delete> <key>\n"
-  "memcache <increment|decrement> <key> [offset]\n"
+  "memcache <increment|decrement> <key> [offset [expires [flags]]]\n"
   "memcache <flush>\n"
   "memcache <status> [verbose]\n";
 
@@ -232,12 +232,20 @@
 			unsigned int offset = 1;
 			switch_bool_t increment = SWITCH_TRUE;
 			char *svalue = NULL;
-			if(argc > 2) {
+			if (argc > 2) {
 				offset = (unsigned int)strtol(argv[2], NULL, 10);
 				svalue = argv[2];
 			} else {
 				svalue = "1";
 			}
+			if(argc > 3) {
+				expires_str = argv[3];
+				expires = (time_t)strtol(expires_str, NULL, 10);
+			}
+			if(argc > 4) {
+				flags_str = argv[4];
+				flags = (uint32_t)strtol(flags_str, NULL, 16);
+			}
 			
 			if (!strcasecmp(subcmd, "increment")) {
 				increment = SWITCH_TRUE;
@@ -251,7 +259,7 @@
 				   Try to add an appropriate initial value.  If someone else beat
 				   us to it, then redo incr/decr.  Otherwise we're good.
 				*/
-				rc = memcached_add(memcached, key, strlen(key), (increment) ? svalue : "0", strlen(svalue), 0, 0);
+				rc = memcached_add(memcached, key, strlen(key), (increment) ? svalue : "0", strlen(svalue), expires, flags);
 				if (rc == MEMCACHED_SUCCESS) {
 					ivalue = (increment) ? offset : 0;
 					switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Initialized inc/dec memcache key: %s to value %d\n", key, offset);