Commits

Anonymous committed 67c6bac

example修正
getsのカスタマイズは後回し

Comments (0)

Files changed (2)

     return 0;
 
 }*/
+static int
+get_multi_all_impl(client_t *client)
+{
 
+}
 
 static int 
-get_multi(void* user, memtext_command cmd, memtext_request_retrieval* req)
+get_multi_all(client_t *client, memtext_command cmd, memtext_request_retrieval* req)
 {
-    client_t *client;
     unsigned i = 0;
     char *c_key;
     size_t c_key_len;
     bool end;
 
-    client = (client_t *)user;
-    client->sended = 1;
-    
 	for(i = 0; i < req->key_num; ++i) {
         c_key = (char *)req->key[i];
 	    c_key_len  = req->key_len[i];
 }
 
 static int 
+get_multi_each(client_t *client, memtext_command cmd, memtext_request_retrieval* req)
+{
+    unsigned i = 0;
+    char *c_key;
+    size_t c_key_len;
+    bool end;
+
+	for(i = 0; i < req->key_num; ++i) {
+        c_key = (char *)req->key[i];
+	    c_key_len  = req->key_len[i];
+        end = (req->key_num -1) == i;
+        printf("end flag !!!!!!!!! %d\n", end);
+        if(get_single_impl(client, c_key, c_key_len, end) < 0){
+            //error
+        }
+    }
+    return 0;
+}
+
+static int 
+get_multi(void* user, memtext_command cmd, memtext_request_retrieval* req)
+{
+    client_t *client;
+    PyObject *app;
+
+    client = (client_t *)user;
+    client->sended = 1;
+    app = client->server->app;
+    
+    /*
+    //check gets method
+    if(PyObject_HasAttrString(app, "gets")){
+        //call gets method
+        printf("call gets\n");
+        return get_multi_all(client, cmd, req);
+    }else{
+        //call get method 
+        return get_multi_each(client, cmd, req);
+    }
+
+    return 0;*/
+    return get_multi_each(client, cmd, req);
+}
+
+static int 
 retrieval(void* user, memtext_command cmd, memtext_request_retrieval* req)
 {
 
     PyObject *method_name = NULL;
     client_t *client;
     client = (client_t *)user;
+    client->sended = 1;
     app = client->server->app;
 
 	const char* const c_key = req->key;
         write_error(client->fd, "Not Implements this command");
         return -1; 
     }
+    
+    if (PyErr_Occurred() || response == NULL){ 
+        write_error(client->fd, "store failed");
+        return -1;
+    }
 
-    str_response = PyObject_Str(response);
-    if (PyErr_Occurred()){ 
-        write_error(client->fd, "set failed");
-        return -1;
+    if(PyBool_Check(response)){
+        //BOOL
+        if(PyObject_IsTrue(response)){
+            str_response = PyString_FromString(STORED);
+        }else{
+            str_response = PyString_FromString(NOT_STORED); 
+        }
+    }else{
+        str_response = PyObject_Str(response);
+        if (PyErr_Occurred()){ 
+            write_error(client->fd, "store failed");
+            return -1;
+        }
     }
 
     char *s;
     Py_ssize_t len;
     if(PyString_AsStringAndSize(str_response, &s, &len)){
-        return 0;
+        return -1;
     }
-    write(client->fd, s, len);
-    client->sended = 1;
+    int ret = write(client->fd, s, len);
     return 0;
 }
 
 print dir()
 
 class Dummy(object):
+    
+    cache = dict()
 
     def get(self, ctx):
-        print "get!!!!!!!! %s " % ctx
-        return ctx
+        print locals()
+        k = ctx['key']
+        return self.cache.get(k, "")
 
     def set(self, ctx):
-        #print locals()
-        print ctx
-        return STORED
+        print locals()
+        k = ctx['key']
+        v = ctx['data']
+        self.cache[k] = v
+        return True
 
     def test(self, *args, **kwargs):
         print args, kwargs