MNodePtr ans;
memcached_return_t rc;
std::vector<MNode*> keywords;
+ MNode* rest;
static paramList kwlist[] = {
{CharConst ("unix"), true},
{CharConst ("inet"), true},
if (obj.mem == NULL) {
throw (ustring (CharConst ("can't connect to the memcached server")));
}
- setParams (arg, 0, NULL, kwlist, &keywords, NULL);
+ setParams (arg, 0, NULL, kwlist, &keywords, &rest);
if (keywords[0]) // #unix
finet = ! eval_bool (keywords[0], mlenv);
if (keywords[1]) // #inet
rc = memcached_behavior_set (obj.mem, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1);
mlenv->setMStack (&obj);
- ans = progn (arg, mlenv);
+ ans = progn (rest, mlenv);
if (mlenv->breaksym ()
&& (mlenv->breaksym ()->isNil () || eq (mlenv->breaksym (), cell->car ()))) {
mlenv->setBreaksym (NULL);
===subfunctions of $memcached===
*/
-/*DOC:
-====cache-set====
- (cache-set KEY VALUE [:expire TIMESEC]) -> NULL
+typedef enum {
+ OP_SET,
+ OP_ADD,
+ OP_REP,
+} cacheop_t;
-*/
-//#SFUNC cache-set ml_memcached_cache_set
-MNode* ml_memcached_cache_set (MNode* cell, MlEnv* mlenv, MLFunc* mobj) {
+static MNode* cache_set (MNode* cell, MlEnv* mlenv, MLFunc* mobj, cacheop_t op) {
MNode* arg = cell->cdr ();
MLMemcached* obj = MObjRef<MLMemcached> (mobj, cMLMemcachedID);
ustring key;
+ MNode* rest;
+ int n;
ustring val;
time_t expire = 0;
memcached_return_t rc;
{NULL, 0, 0}
};
- setParams (arg, 2, ¶ms, kwlist, &keywords, NULL);
+ setParams (arg, 1, ¶ms, kwlist, &keywords, &rest);
key = eval_str (params[0], mlenv);
- val = eval_str (params[1], mlenv);
if (keywords[0]) {
expire = eval_int (keywords[0], mlenv);
}
+ n = 0;
+ while (rest) {
+ if (n > 0)
+ val.append (1, '\0');
+ val.append (eval_str (rest->car (), mlenv));
+ nextNode (rest);
+ n ++;
+ }
- rc = memcached_set (obj->mem, key.data (), key.length (), val.data (), val.length (), expire, 0);
+ switch (op) {
+ case OP_SET:
+ rc = memcached_set (obj->mem, key.data (), key.length (), val.data (), val.length (), expire, 0);
+ break;
+ case OP_ADD:
+ rc = memcached_add (obj->mem, key.data (), key.length (), val.data (), val.length (), expire, 0);
+ break;
+ case OP_REP:
+ rc = memcached_replace (obj->mem, key.data (), key.length (), val.data (), val.length (), expire, 0);
+ break;
+ default:;
+ }
return NULL;
}
/*DOC:
+====cache-set====
+ (cache-set KEY VALUES... [:expire TIMESEC]) -> NULL
+====cache-add====
+ (cache-add KEY VALUES... [:expire TIMESEC]) -> NULL
+====cache-replace====
+ (cache-replace KEY VALUES... [:expire TIMESEC]) -> NULL
+
+*/
+//#SFUNC cache-set ml_memcached_cache_set
+//#SFUNC cache-add ml_memcached_cache_add
+//#SFUNC cache-replace ml_memcached_cache_replace
+MNode* ml_memcached_cache_set (MNode* cell, MlEnv* mlenv, MLFunc* mobj) {
+ return cache_set (cell, mlenv, mobj, OP_SET);
+}
+
+MNode* ml_memcached_cache_add (MNode* cell, MlEnv* mlenv, MLFunc* mobj) {
+ return cache_set (cell, mlenv, mobj, OP_ADD);
+}
+
+MNode* ml_memcached_cache_replace (MNode* cell, MlEnv* mlenv, MLFunc* mobj) {
+ return cache_set (cell, mlenv, mobj, OP_REP);
+}
+
+/*DOC:
====cache-get====
- (cache-get KEY) -> STRING
+ (cache-get KEY) -> STRING-LIST or NIL
*/
//#SFUNC cache-get ml_memcached_cache_get
size_t valLen = 0;
uint32_t flag;
memcached_return_t rc;
- MNode* ans = NULL;
+ MNodeList ans;
if (!arg)
throw (uErrorWrongNumber);
val = memcached_get (obj->mem, key.data (), key.length (), &valLen, &flag, &rc);
if (val) {
- ans = newMNode_str (new ustring (val, valLen));
+ ustring u (val, valLen);
+ uiterator b = u.begin ();
+ uiterator e = u.end ();
+ uiterator it;
+
+ for (it = b; ; it ++) {
+ if (*it == 0 || it == e) {
+ ans.append (newMNode_str (new ustring (b, it)));
+ b = it + 1;
+ if (it == e)
+ break;
+ }
+ }
}
- return ans;
+ return ans.release ();
}
/*DOC: