1. paintcan
  2. pylibcb

Commits

Sebastian Hubbard  committed 489b339

integerated expiry, working on cas

  • Participants
  • Parent commits a48c3ca
  • Branches default

Comments (0)

Files changed (1)

File pylibcb.c

View file
   PyObject *cb;
   void *key, *val;
   int nkey, nval;
+  unsigned long _expiry = 0;
+  unsigned long cas = 0;
 
-  if (!PyArg_ParseTuple(args, "Os#s#", &cb, &key, &nkey, &val, &nval))
+  if (!PyArg_ParseTuple(args, "Os#s#|kk", &cb, &key, &nkey, &val, &nval, &_expiry, &cas))
     return 0;
   if (!pyobject_is_pylibcb_instance(cb))
     return 0;
   set_context(cb);
 
-  libcouchbase_store_by_key(context->cb, hand_out_ticket(new_ticket()), LIBCOUCHBASE_SET, 0, 0, key, nkey, val, nval, 0, 0, 0);
+  time_t expiry = _expiry;
+
+  libcouchbase_store_by_key(context->cb, hand_out_ticket(new_ticket()), LIBCOUCHBASE_SET, 0, 0, 
+			    key, nkey, val, nval, 0, expiry, cas);
   libcouchbase_wait(context->cb);
   INTERNAL_EXCEPTION_HANDLER(return 0);
 
   PyObject *cb;
   void *key;
   int nkey;
+  unsigned long cas = 0;
 
-  if (!PyArg_ParseTuple(args, "Os#", &cb, &key, &nkey))
+  if (!PyArg_ParseTuple(args, "Os#|k", &cb, &key, &nkey, &cas))
     return 0;
   if (!pyobject_is_pylibcb_instance(cb))
     return 0;
   set_context(cb);
 
-  libcouchbase_remove_by_key(context->cb, hand_out_ticket(new_ticket()), 0, 0, key, nkey, 0);
+  libcouchbase_remove_by_key(context->cb, hand_out_ticket(new_ticket()), 0, 0, key, nkey, cas);
   libcouchbase_wait(context->cb);
   INTERNAL_EXCEPTION_HANDLER(return 0);
 
   const void * const key;
   int _nkey;
   int usec = 0;
-
-  if (!PyArg_ParseTuple(args, "Os#|i", &cb, &key, &_nkey, &usec))
+  unsigned long _expiry = 0;
+  int return_cas = 0;
+  
+  if (!PyArg_ParseTuple(args, "Os#|iki", &cb, &key, &_nkey, &usec, &_expiry, &return_cas))
     return 0;
   if (!pyobject_is_pylibcb_instance(cb))
     return 0;  
 
   int *ticket = new_ticket();
   libcouchbase_size_t nkey = _nkey;
+  time_t expiry = _expiry;
 
   if (usec)
     create_timeout(usec, hand_out_ticket(ticket));
-  libcouchbase_mget_by_key(context->cb, hand_out_ticket(ticket), 0, 0, 1, &key, &nkey, 0);
+  libcouchbase_mget_by_key(context->cb, hand_out_ticket(ticket), 0, 0, 1, &key, &nkey, _expiry ? &expiry : 0);
 
   while (!context->timed_out && !context->succeeded && !context->exception && !context->internal_exception)
     libcouchbase_wait(context->cb);
     return Py_None;
   }
 
+  if (return_cas)
+    return Py_BuildValue("s#k", context->returned_value.contents, context->returned_value.filled,
+			(unsigned long) context->returned_cas);
   return Py_BuildValue("s#", context->returned_value.contents, context->returned_value.filled);
 }