--- parser3/src/classes/memcached.C 2012/06/17 21:46:47 1.7 +++ parser3/src/classes/memcached.C 2020/12/15 17:10:29 1.16 @@ -1,7 +1,7 @@ /** @file Parser: memcached class. - Copyright (c) 2001-2012 Art. Lebedev Studio (http://www.artlebedev.com) + Copyright (c) 2001-2020 Art. Lebedev Studio (http://www.artlebedev.com) Authors: Ivan Poluyanov Artem Stepanov @@ -15,7 +15,7 @@ #include "pa_vbool.h" #include "pa_vmemcached.h" -volatile const char * IDENT_MEMCACHED_C="$Id: memcached.C,v 1.7 2012/06/17 21:46:47 moko Exp $"; +volatile const char * IDENT_MEMCACHED_C="$Id: memcached.C,v 1.16 2020/12/15 17:10:29 moko Exp $"; class MMemcached: public Methoded { public: // VStateless_class @@ -24,7 +24,7 @@ public: MMemcached(); }; -DECLARE_CLASS_VAR(memcached, new MMemcached, 0); +DECLARE_CLASS_VAR(memcached, new MMemcached); static void _open(Request& r, MethodParams& params) { VMemcached& self=GET_SELF(r, VMemcached); @@ -32,9 +32,12 @@ static void _open(Request& r, MethodPara time_t ttl=params.count()>1 ? params.as_int(1, "default expiration must be int", r) : 0; if(HashStringValue* options=param_value.get_hash()){ + bool connect=true; String result; for(HashStringValue::Iterator i(*options); i; i.next()){ - if(Value *b=i.value()->as("bool")){ + if(i.key() == "skip-connect"){ + connect=!i.value()->as_bool(); + } else if(Value *b=i.value()->as("bool")){ if(b->as_bool()) result << (result.is_empty() ? "--" : " --") << i.key(); } else { @@ -43,14 +46,14 @@ static void _open(Request& r, MethodPara result << (result.is_empty() ? "--" : " --") << i.key() << "=" << value; } } - self.open(result, ttl); + self.open(result, ttl, connect); } else { const String& connect_string=params.as_string(0, "param must be connection string or options hash"); self.open_parse(connect_string, ttl); } } -static void _flush(Request& r, MethodParams& params) { +static void _clear(Request& r, MethodParams& params) { VMemcached& self=GET_SELF(r, VMemcached); time_t ttl=(params.count()>0) ? params.as_int(0, "expiration must be int", r) : 0; @@ -69,7 +72,7 @@ static void _mget(Request& r, MethodPara keys+=¶ms.as_string(i, "key must be string"); } - r.write_no_lang(self.mget(keys)); + r.write(self.mget(keys)); } else { Table* table=param.get_table(); if(table==0){ @@ -82,7 +85,7 @@ static void _mget(Request& r, MethodPara keys+=table->get(i)->get(0); } - r.write_no_lang(self.mget(keys)); + r.write(self.mget(keys)); } } @@ -90,7 +93,7 @@ static void _add(Request& r, MethodParam VMemcached& self=GET_SELF(r, VMemcached); const String& key=params.as_string(0, "key must be string"); - r.write_no_lang(VBool::get(self.add(key, ¶ms.as_no_junction(1, PARAM_MUST_NOT_BE_CODE)))); + r.write(VBool::get(self.add(key, ¶ms.as_no_junction(1, PARAM_MUST_NOT_BE_CODE)))); } static void _delete(Request& r, MethodParams& params) { @@ -100,10 +103,17 @@ static void _delete(Request& r, MethodPa self.remove(key); } +static void _release(Request& r, MethodParams&) { + VMemcached& self=GET_SELF(r, VMemcached); + + self.quit(); +} + MMemcached::MMemcached() : Methoded("memcached") { add_native_method("open", Method::CT_DYNAMIC, _open, 1, 2); - add_native_method("flush", Method::CT_DYNAMIC, _flush, 0, 1); + add_native_method("clear", Method::CT_DYNAMIC, _clear, 0, 1); add_native_method("mget", Method::CT_DYNAMIC, _mget, 1, 1000); add_native_method("add", Method::CT_DYNAMIC, _add, 2, 2); add_native_method("delete", Method::CT_DYNAMIC, _delete, 1, 1); + add_native_method("release", Method::CT_DYNAMIC, _release, 0, 0); }