--- parser3/src/classes/memcached.C 2012/03/19 22:19:27 1.1 +++ parser3/src/classes/memcached.C 2012/04/22 22:06:50 1.3 @@ -11,9 +11,10 @@ #include "pa_request.h" #include "pa_vstring.h" +#include "pa_vtable.h" #include "pa_vmemcached.h" -volatile const char * IDENT_MEMCACHED_C="$Id: memcached.C,v 1.1 2012/03/19 22:19:27 moko Exp $"; +volatile const char * IDENT_MEMCACHED_C="$Id: memcached.C,v 1.3 2012/04/22 22:06:50 moko Exp $"; class MMemcached: public Methoded { public: // VStateless_class @@ -25,9 +26,67 @@ public: DECLARE_CLASS_VAR(memcached, new MMemcached, 0); static void _open(Request& r, MethodParams& params) { - const String& connect_string=params.as_string(0, "connection string must be string"); + Value& param_value=params.as_no_junction(0, PARAM_MUST_NOT_BE_CODE); VMemcached& self=GET_SELF(r, VMemcached); - self.open(connect_string); + + int ttl=0; + + if(params.count()>1) + ttl=params.as_int(1, "default expiration must be int", r); + + if(HashStringValue* options=param_value.get_hash()){ + String result; + for(HashStringValue::Iterator i(*options); i; i.next()){ + result << (result.is_empty() ? "--" : " --") << i.key(); + const String& value=i.value()->as_string(); + if(!value.is_empty()) + result << "=" << value; + } + self.open(result, ttl); + } 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) { + int ttl=0; + + if(params.count()>0) + params.as_int(0, "expiration must be int", r); + + VMemcached& self=GET_SELF(r, VMemcached); + self.flush(ttl); +} + +static void _mget(Request& r, MethodParams& params) { + Value& param=params.as_no_junction(0, PARAM_MUST_NOT_BE_CODE); + + VMemcached& self=GET_SELF(r, VMemcached); + + if(param.is_string()){ + + ArrayString keys(params.count()); + + for(size_t i=0; icount()); + + for(size_t i=0; icount(); i++) { + keys+=table->get(i)->get(0); + } + + r.write_no_lang(self.mget(keys)); + } } static void _delete(Request& r, MethodParams& params) { @@ -38,6 +97,8 @@ static void _delete(Request& r, MethodPa } MMemcached::MMemcached() : Methoded("memcached") { - add_native_method("open", Method::CT_DYNAMIC, _open, 1, 1); + add_native_method("open", Method::CT_DYNAMIC, _open, 1, 2); + add_native_method("flush", Method::CT_DYNAMIC, _flush, 1, 1); + add_native_method("mget", Method::CT_DYNAMIC, _mget, 1, 1000); add_native_method("delete", Method::CT_DYNAMIC, _delete, 1, 1); }