From 3df58550ddc027414e98e5a21e1dded8d8458d4b Mon Sep 17 00:00:00 2001 From: Danilo Chang Date: Tue, 22 Nov 2016 07:29:06 +0800 Subject: [PATCH 1/2] Add prepend and flush command --- README.md | 4 ++++ generic/tclMemcache.c | 33 ++++++++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 913524f..c1cc662 100644 --- a/README.md +++ b/README.md @@ -64,12 +64,16 @@ Available Commands memcache append key value ?expires? ?flags? + memcache prepend key value ?expires? ?flags? + memcache set key value ?expires? ?flags? memcache replace key value ?expires? ?flags? memcache delete key ?expires? + memcache flush ?expires? + memcache incr key value ?varname? memcache decr key value ?varname? diff --git a/generic/tclMemcache.c b/generic/tclMemcache.c index 5960234..34f1f90 100644 --- a/generic/tclMemcache.c +++ b/generic/tclMemcache.c @@ -65,13 +65,13 @@ static int Memcache_Cmd(ClientData arg, Tcl_Interp * interp, int objc, Tcl_Obj * // list of supported commands that we expose. enum { - cmdGet, cmdAdd, cmdAppend, cmdSet, cmdReplace, - cmdDelete, cmdIncr, cmdDecr, cmdVersion, cmdServer, cmdBehavior + cmdGet, cmdAdd, cmdAppend, cmdPrepend, cmdSet, cmdReplace, + cmdDelete, cmdFlush, cmdIncr, cmdDecr, cmdVersion, cmdServer, cmdBehavior }; static CONST char *sCmd[] = { - "get", "add", "append", "set", "replace", - "delete", "incr", "decr", "version", "server", "behavior", + "get", "add", "append", "prepend", "set", "replace", + "delete", "flush", "incr", "decr", "version", "server", "behavior", 0 }; @@ -186,12 +186,14 @@ static int Memcache_Cmd(ClientData arg, Tcl_Interp * interp, int objc, Tcl_Obj * case cmdAdd: case cmdSet: case cmdAppend: + case cmdPrepend: case cmdReplace: /* * Store a new value into the cache: * * - memcache add key value ?expires? ?flags? * - memcache append key value ?expires? ?flags? + * - memcache prepend key value ?expires? ?flags? * - memcache set key value ?expires? ?flags? * - memcache replace key value ?expires? ?flags? */ @@ -214,6 +216,9 @@ static int Memcache_Cmd(ClientData arg, Tcl_Interp * interp, int objc, Tcl_Obj * case cmdAppend: result = memcached_append(get_memc(), key, strlen(key), data, isize, expires, flags); break; + case cmdPrepend: + result = memcached_prepend(get_memc(), key, strlen(key), data, isize, expires, flags); + break; case cmdSet: result = memcached_set(get_memc(), key, strlen(key), data, isize, expires, flags); break; @@ -224,7 +229,7 @@ static int Memcache_Cmd(ClientData arg, Tcl_Interp * interp, int objc, Tcl_Obj * Tcl_SetObjResult(interp, Tcl_NewIntObj(result)); break; - + case cmdDelete: /* * Delete an existing value from the cache (if it exists): @@ -243,6 +248,24 @@ static int Memcache_Cmd(ClientData arg, Tcl_Interp * interp, int objc, Tcl_Obj * Tcl_SetObjResult(interp, Tcl_NewIntObj(result)); break; + + case cmdFlush: + /* + * Wipe clean the contents of memcached servers: + * + * - memcache flush ?expires? + */ + if (objc != 2 && objc != 3) { + Tcl_WrongNumArgs(interp, 2, objv, "?expires?"); + return TCL_ERROR; + } + if (objc == 3) { + expires = atoi(Tcl_GetString(objv[2])); + } + result = memcached_flush(get_memc(), expires); + Tcl_SetObjResult(interp, Tcl_NewIntObj(result)); + break; + case cmdIncr: case cmdDecr: From fca53557436c31b659402bfe33276a45267af4f3 Mon Sep 17 00:00:00 2001 From: Danilo Chang Date: Tue, 22 Nov 2016 08:57:24 +0800 Subject: [PATCH 2/2] Update ChangeLog --- ChangeLog | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ChangeLog b/ChangeLog index efddd91..3d369a7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2016-11-22 Danilo Chang + + Add prepend and flush command + 2016-11-11 Jeff Lawson Release of version 1.2.0