Skip to content

Commit

Permalink
Merge pull request #2 from ray2501/master
Browse files Browse the repository at this point in the history
Add prepend and flush command
  • Loading branch information
bovine authored Nov 22, 2016
2 parents 21e28d9 + fca5355 commit 23fbdf2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2016-11-22 Danilo Chang <[email protected]>

Add prepend and flush command

2016-11-11 Jeff Lawson <[email protected]>

Release of version 1.2.0
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
33 changes: 28 additions & 5 deletions generic/tclMemcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down Expand Up @@ -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?
*/
Expand All @@ -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;
Expand All @@ -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):
Expand All @@ -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:
Expand Down

0 comments on commit 23fbdf2

Please sign in to comment.