1 Star 0 Fork 347

黑冰/swoole-src

forked from swoole/swoole-src 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
swoole_redis_coro.cc 148.93 KB
一键复制 编辑 原始数据 按行查看 历史
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587
/*
+----------------------------------------------------------------------+
| Swoole |
+----------------------------------------------------------------------+
| This source file is subject to version 2.0 of the Apache license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.apache.org/licenses/LICENSE-2.0.html |
| If you did not receive a copy of the Apache2.0 license and are unable|
| to obtain it through the world-wide-web, please send a note to |
| license@swoole.com so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Tianfeng Han <mikan.tenny@gmail.com> |
+----------------------------------------------------------------------+
*/
#include "php_swoole_cxx.h"
#include "swoole_coroutine.h"
#include "thirdparty/hiredis/hiredis.h"
#include "thirdparty/hiredis/async.h"
#include "ext/standard/php_var.h"
using namespace swoole;
#define SW_REDIS_COMMAND_ALLOC_ARGS_ARR zval *z_args = (zval *) emalloc(argc*sizeof(zval));
#define SW_REDIS_COMMAND_ARGS_TYPE(arg) Z_TYPE(arg)
#define SW_REDIS_COMMAND_ARGS_LVAL(arg) Z_LVAL(arg)
#define SW_REDIS_COMMAND_ARGS_DVAL(arg) Z_DVAL(arg)
#define SW_REDIS_COMMAND_ARGS_ARRVAL(arg) Z_ARRVAL(arg)
#define SW_REDIS_COMMAND_ARGS_STRVAL(arg) Z_STRVAL(arg)
#define SW_REDIS_COMMAND_ARGS_STRLEN(arg) Z_STRLEN(arg)
#define SW_REDIS_COMMAND_ARGS_REF(arg) &arg
#define SW_REDIS_COMMAND_BUFFER_SIZE 64
#define SW_BITOP_MIN_OFFSET 0
#define SW_BITOP_MAX_OFFSET 4294967295
#define SW_REDIS_TYPE_NOT_FOUND 0
#define SW_REDIS_TYPE_STRING 1
#define SW_REDIS_TYPE_SET 2
#define SW_REDIS_TYPE_LIST 3
#define SW_REDIS_TYPE_ZSET 4
#define SW_REDIS_TYPE_HASH 5
/* The same errCode define with hiredis */
enum swRedisError
{
SW_REDIS_ERR_IO = 1, /* Error in read or write */
SW_REDIS_ERR_OTHER = 2, /* Everything else... */
SW_REDIS_ERR_EOF = 3, /* End of file */
SW_REDIS_ERR_PROTOCOL = 4, /* Protocol error */
SW_REDIS_ERR_OOM = 5, /* Out of memory */
SW_REDIS_ERR_CLOSED = 6, /* Closed */
SW_REDIS_ERR_NOAUTH = 7, /* Authentication required */
SW_REDIS_ERR_ALLOC = 8, /* Alloc failed */
};
/* Extended SET argument detection */
#define IS_EX_ARG(a) \
((a[0]=='e' || a[0]=='E') && (a[1]=='x' || a[1]=='X') && a[2]=='\0')
#define IS_PX_ARG(a) \
((a[0]=='p' || a[0]=='P') && (a[1]=='x' || a[1]=='X') && a[2]=='\0')
#define IS_NX_ARG(a) \
((a[0]=='n' || a[0]=='N') && (a[1]=='x' || a[1]=='X') && a[2]=='\0')
#define IS_XX_ARG(a) \
((a[0]=='x' || a[0]=='X') && (a[1]=='x' || a[1]=='X') && a[2]=='\0')
static zend_class_entry *swoole_redis_coro_ce;
static zend_object_handlers swoole_redis_coro_handlers;
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_construct, 0, 0, 0)
ZEND_ARG_INFO(0, config)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_connect, 0, 0, 1)
ZEND_ARG_INFO(0, host)
ZEND_ARG_INFO(0, port)
ZEND_ARG_INFO(0, serialize)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_setOptions, 0, 0, 1)
ZEND_ARG_INFO(0, options)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_setDefer, 0, 0, 1)
ZEND_ARG_INFO(0, defer)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_void, 0, 0, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_key, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_key_value, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_key_long, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, integer)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_request, 0, 0, 1)
ZEND_ARG_ARRAY_INFO(0, params, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_append, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_auth, 0, 0, 1)
ZEND_ARG_INFO(0, password)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_bgSave, 0, 0, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_bgrewriteaof, 0, 0, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_bitcount, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_bitop, 0, 0, 3)
ZEND_ARG_INFO(0, operation)
ZEND_ARG_INFO(0, ret_key)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, other_keys)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_blPop, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, timeout_or_key)
ZEND_ARG_INFO(0, extra_args)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_brPop, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, timeout_or_key)
ZEND_ARG_INFO(0, extra_args)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_brpoplpush, 0, 0, 3)
ZEND_ARG_INFO(0, src)
ZEND_ARG_INFO(0, dst)
ZEND_ARG_INFO(0, timeout)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_close, 0, 0, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_dbSize, 0, 0, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_debug, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_decr, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_decrBy, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_dump, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_eval, 0, 0, 1)
ZEND_ARG_INFO(0, script)
ZEND_ARG_INFO(0, args)
ZEND_ARG_INFO(0, num_keys)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_evalsha, 0, 0, 1)
ZEND_ARG_INFO(0, script_sha)
ZEND_ARG_INFO(0, args)
ZEND_ARG_INFO(0, num_keys)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_exec, 0, 0, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_exists, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, other_keys)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_expireAt, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, timestamp)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_flushAll, 0, 0, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_flushDB, 0, 0, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_get, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_getBit, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, offset)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_getKeys, 0, 0, 1)
ZEND_ARG_INFO(0, pattern)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_getRange, 0, 0, 3)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, start)
ZEND_ARG_INFO(0, end)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_getSet, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_hDel, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, member)
ZEND_ARG_INFO(0, other_members)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_hExists, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, member)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_hGet, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, member)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_hGetAll, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_hIncrBy, 0, 0, 3)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, member)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_hIncrByFloat, 0, 0, 3)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, member)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_hKeys, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_hLen, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_hMget, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, keys)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_hMset, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, pairs)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_hSet, 0, 0, 3)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, member)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_hSetNx, 0, 0, 3)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, member)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_hVals, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_incr, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_incrBy, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_incrByFloat, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_lGet, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, index)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_lGetRange, 0, 0, 3)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, start)
ZEND_ARG_INFO(0, end)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_lInsert, 0, 0, 4)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, position)
ZEND_ARG_INFO(0, pivot)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_lPop, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_lPush, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_lPushx, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_lRemove, 0, 0, 3)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, value)
ZEND_ARG_INFO(0, count)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_lSet, 0, 0, 3)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, index)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_lSize, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_lastSave, 0, 0, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_listTrim, 0, 0, 3)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, start)
ZEND_ARG_INFO(0, stop)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_move, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, dbindex)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_mset, 0, 0, 1)
ZEND_ARG_INFO(0, pairs)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_msetnx, 0, 0, 1)
ZEND_ARG_INFO(0, pairs)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_multi, 0, 0, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_persist, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_pexpire, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, timestamp)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_pexpireAt, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, timestamp)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_pfadd, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, elements)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_pfcount, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_pfmerge, 0, 0, 2)
ZEND_ARG_INFO(0, dstkey)
ZEND_ARG_INFO(0, keys)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_ping, 0, 0, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_psetex, 0, 0, 3)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, expire)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_psubscribe, 0, 0, 1)
ZEND_ARG_INFO(0, patterns)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_punsubscribe, 0, 0, 1)
ZEND_ARG_INFO(0, patterns)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_pttl, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_publish, 0, 0, 2)
ZEND_ARG_INFO(0, channel)
ZEND_ARG_INFO(0, message)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_rPop, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_rPush, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_rPushx, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_randomKey, 0, 0, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_renameKey, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, newkey)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_renameNx, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, newkey)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_restore, 0, 0, 3)
ZEND_ARG_INFO(0, ttl)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_role, 0, 0, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_rpoplpush, 0, 0, 2)
ZEND_ARG_INFO(0, src)
ZEND_ARG_INFO(0, dst)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_sAdd, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_sContains, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_sDiff, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, other_keys)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_sDiffStore, 0, 0, 2)
ZEND_ARG_INFO(0, dst)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, other_keys)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_sInter, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, other_keys)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_sInterStore, 0, 0, 2)
ZEND_ARG_INFO(0, dst)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, other_keys)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_sMembers, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_sMove, 0, 0, 3)
ZEND_ARG_INFO(0, src)
ZEND_ARG_INFO(0, dst)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_sPop, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_sRandMember, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, count)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_sRemove, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_sSize, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_sUnion, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, other_keys)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_sUnionStore, 0, 0, 2)
ZEND_ARG_INFO(0, dst)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, other_keys)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_save, 0, 0, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_script, 0, 0, 1)
ZEND_ARG_INFO(0, cmd)
ZEND_ARG_INFO(0, args)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_select, 0, 0, 1)
ZEND_ARG_INFO(0, dbindex)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_set, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, value)
ZEND_ARG_INFO(0, timeout)
ZEND_ARG_INFO(0, opt)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_setBit, 0, 0, 3)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, offset)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_setRange, 0, 0, 3)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, offset)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_setTimeout, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, timeout)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_setex, 0, 0, 3)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, expire)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_setnx, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_strlen, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_subscribe, 0, 0, 1)
ZEND_ARG_INFO(0, channels)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_unsubscribe, 0, 0, 1)
ZEND_ARG_INFO(0, channels)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_time, 0, 0, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_ttl, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_type, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_unwatch, 0, 0, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_watch, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, other_keys)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_zAdd, 0, 0, 3)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, score)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_zCard, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_zCount, 0, 0, 3)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, min)
ZEND_ARG_INFO(0, max)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_zDelete, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, member)
ZEND_ARG_INFO(0, other_members)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_zDeleteRangeByRank, 0, 0, 3)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, start)
ZEND_ARG_INFO(0, end)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_zDeleteRangeByScore, 0, 0, 3)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, min)
ZEND_ARG_INFO(0, max)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_zIncrBy, 0, 0, 3)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, value)
ZEND_ARG_INFO(0, member)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_zInter, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, keys)
ZEND_ARG_INFO(0, weights)
ZEND_ARG_INFO(0, aggregate)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_zRange, 0, 0, 3)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, start)
ZEND_ARG_INFO(0, end)
ZEND_ARG_INFO(0, scores)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_zRangeByLex, 0, 0, 3)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, min)
ZEND_ARG_INFO(0, max)
ZEND_ARG_INFO(0, offset)
ZEND_ARG_INFO(0, limit)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_zRangeByScore, 0, 0, 3)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, start)
ZEND_ARG_INFO(0, end)
ZEND_ARG_INFO(0, options)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_zRank, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, member)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_zRevRange, 0, 0, 3)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, start)
ZEND_ARG_INFO(0, end)
ZEND_ARG_INFO(0, scores)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_zRevRangeByLex, 0, 0, 3)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, min)
ZEND_ARG_INFO(0, max)
ZEND_ARG_INFO(0, offset)
ZEND_ARG_INFO(0, limit)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_zRevRangeByScore, 0, 0, 3)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, start)
ZEND_ARG_INFO(0, end)
ZEND_ARG_INFO(0, options)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_zRevRank, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, member)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_zScore, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, member)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_zUnion, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, keys)
ZEND_ARG_INFO(0, weights)
ZEND_ARG_INFO(0, aggregate)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_del, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, other_keys)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_lLen, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_lrange, 0, 0, 3)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, start)
ZEND_ARG_INFO(0, end)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_lrem, 0, 0, 3)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, value)
ZEND_ARG_INFO(0, count)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_ltrim, 0, 0, 3)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, start)
ZEND_ARG_INFO(0, stop)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_mget, 0, 0, 1)
ZEND_ARG_INFO(0, keys)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_rename, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, newkey)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_scard, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_zRem, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, member)
ZEND_ARG_INFO(0, other_members)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_zRemRangeByRank, 0, 0, 3)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, min)
ZEND_ARG_INFO(0, max)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_zRemRangeByScore, 0, 0, 3)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, min)
ZEND_ARG_INFO(0, max)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_zRemove, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, member)
ZEND_ARG_INFO(0, other_members)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_zSize, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_zinterstore, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, keys)
ZEND_ARG_INFO(0, weights)
ZEND_ARG_INFO(0, aggregate)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_redis_coro_zunionstore, 0, 0, 2)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, keys)
ZEND_ARG_INFO(0, weights)
ZEND_ARG_INFO(0, aggregate)
ZEND_END_ARG_INFO()
#define IS_EX_PX_ARG(a) (IS_EX_ARG(a) || IS_PX_ARG(a))
#define IS_NX_XX_ARG(a) (IS_NX_ARG(a) || IS_XX_ARG(a))
#define SW_REDIS_COMMAND_CHECK \
Coroutine::get_current_safe(); \
swRedisClient *redis = swoole_get_redis_client(getThis());
#define SW_REDIS_COMMAND_ARGV_FILL(str, str_len) \
argvlen[i] = str_len; \
argv[i] = estrndup(str, str_len); \
i++;
#define SW_REDIS_COMMAND_ARGV_FILL_WITH_SERIALIZE(_val) \
if (redis->serialize) { \
smart_str sstr = {0}; \
php_serialize_data_t s_ht; \
PHP_VAR_SERIALIZE_INIT(s_ht); \
php_var_serialize(&sstr, _val, &s_ht); \
argvlen[i] = (size_t)sstr.s->len; \
argv[i] = estrndup(sstr.s->val, sstr.s->len); \
zend_string_release(sstr.s); \
PHP_VAR_SERIALIZE_DESTROY(s_ht); \
} else { \
zend_string *convert_str = zval_get_string(_val); \
argvlen[i] = ZSTR_LEN(convert_str); \
argv[i] = estrndup(ZSTR_VAL(convert_str), ZSTR_LEN(convert_str)); \
zend_string_release(convert_str); \
} \
i++;
#define SW_REDIS_COMMAND_ALLOC_ARGV \
size_t stack_argvlen[SW_REDIS_COMMAND_BUFFER_SIZE]; \
char *stack_argv[SW_REDIS_COMMAND_BUFFER_SIZE]; \
size_t *argvlen; \
char **argv; \
if (argc > SW_REDIS_COMMAND_BUFFER_SIZE) \
{ \
argvlen = (size_t *) emalloc(sizeof(size_t) * (argc)); \
argv = (char **) emalloc(sizeof(char*) * (argc)); \
} \
else \
{ \
argvlen = stack_argvlen; \
argv = stack_argv; \
}
#define SW_REDIS_COMMAND_FREE_ARGV \
if (argv != stack_argv) \
{ \
efree(argvlen); \
efree(argv); \
}
typedef struct
{
redisContext *context;
struct {
bool auth;
long db_num;
bool subscribe;
} session;
double connect_timeout;
double timeout;
bool serialize;
bool defer;
uint8_t reconnect_interval;
uint8_t reconnected_count;
bool auth;
long database;
zval *zobject;
zval _zobject;
} swRedisClient;
typedef struct
{
zval _value;
zval *value;
swRedisClient *redis;
} swRedis_result;
enum {SW_REDIS_MODE_MULTI, SW_REDIS_MODE_PIPELINE};
static void swoole_redis_coro_parse_result(swRedisClient *redis, zval* return_value, redisReply* reply);
static sw_inline swRedisClient* swoole_get_redis_client(zval *zobject)
{
swRedisClient *redis = (swRedisClient *) swoole_get_object(zobject);
if (UNEXPECTED(!redis))
{
swoole_php_fatal_error(E_ERROR, "you must call Redis constructor first");
}
return redis;
}
static sw_inline Socket* swoole_redis_coro_get_socket(redisContext *context)
{
if (context->fd > 0)
{
swConnection *conn = swReactor_get(SwooleG.main_reactor, context->fd);
return conn ? (Socket *) conn->object : nullptr;
}
return nullptr;
}
static sw_inline int sw_redis_convert_err(int err)
{
switch (err)
{
case SW_REDIS_ERR_IO:
return errno;
case SW_REDIS_ERR_EOF:
case SW_REDIS_ERR_CLOSED:
return ECONNRESET;
case SW_REDIS_ERR_OTHER:
return EINVAL;
case SW_REDIS_ERR_OOM:
case SW_REDIS_ERR_ALLOC:
return ENOMEM;
case SW_REDIS_ERR_PROTOCOL:
return EPROTO;
case SW_REDIS_ERR_NOAUTH:
return EACCES;
case 0:
return 0;
default:
return errno;
}
}
static sw_inline bool swoole_redis_coro_close(swRedisClient *redis)
{
if (redis->context)
{
Socket *socket = swoole_redis_coro_get_socket(redis->context);
swTraceLog(SW_TRACE_REDIS_CLIENT, "redis connection closed, fd=%d", redis->context->fd);
zend_update_property_bool(swoole_redis_coro_ce, redis->zobject, ZEND_STRL("connected"), 0);
if (!(socket && socket->has_bound()))
{
redisFreeKeepFd(redis->context);
redis->context = NULL;
redis->session = { false, 0, false };
}
if (socket && socket->close())
{
delete socket;
}
return true;
}
return false;
}
static bool redis_auth(swRedisClient *redis, char *pw, size_t pw_len);
static bool redis_select_db(swRedisClient *redis, long db_number);
static void redis_request(swRedisClient *redis, int argc, char **argv, size_t *argvlen, zval *return_value, bool retry = false);
static bool swoole_redis_coro_connect(swRedisClient *redis)
{
zval *zobject = redis->zobject;
redisContext *context;
Socket *socket;
struct timeval tv;
zval *ztmp;
zval *zhost = sw_zend_read_property(swoole_redis_coro_ce, zobject, ZEND_STRL("host"), 0);
zval *zport = sw_zend_read_property(swoole_redis_coro_ce, zobject, ZEND_STRL("port"), 0);
zend::string host(zhost);
zend_long port = zval_get_long(zport);
if (host.len() == 0)
{
swoole_php_fatal_error(E_WARNING, "The host is empty");
return false;
}
if (redis->context)
{
context = redis->context;
if (
context->connection_type == REDIS_CONN_TCP &&
strcmp(context->tcp.host, host.val()) == 0 && context->tcp.port == port
)
{
return true;
}
else if (
context->connection_type == REDIS_CONN_UNIX &&
(strstr(host.val(), context->unix_sock.path) - host.val()) + strlen(context->unix_sock.path) == host.len()
)
{
return true;
}
else
{
swoole_redis_coro_close(redis);
}
}
php_swoole_check_reactor();
if (redis->connect_timeout > 0)
{
tv.tv_sec = redis->connect_timeout;
tv.tv_usec = (redis->connect_timeout - (double) tv.tv_sec) * 1000 * 1000;
}
if (strncasecmp(host.val(), ZEND_STRL("unix:/")) == 0)
{
context = redisConnectUnixWithTimeout(host.val() + 5 + strspn(host.val() + 5, "/") - 1, tv);
}
else
{
if (port <= 0 || port > SW_CLIENT_MAX_PORT)
{
swoole_php_fatal_error(E_WARNING, "The port " ZEND_LONG_FMT " is invalid", port);
return false;
}
context = redisConnectWithTimeout(host.val(), (int) port, tv);
}
redis->context = context;
if (!context)
{
zend_update_property_long(swoole_redis_coro_ce, zobject, ZEND_STRL("errType"), SW_REDIS_ERR_ALLOC);
zend_update_property_long(swoole_redis_coro_ce, zobject, ZEND_STRL("errCode"), sw_redis_convert_err(SW_REDIS_ERR_ALLOC));
zend_update_property_string(swoole_redis_coro_ce, zobject, ZEND_STRL("errMsg"), "cannot allocate redis context");
return false;
}
if (context->err)
{
zend_update_property_long(swoole_redis_coro_ce, zobject, ZEND_STRL("errType"), context->err);
zend_update_property_long(swoole_redis_coro_ce, zobject, ZEND_STRL("errCode"), sw_redis_convert_err(context->err));
zend_update_property_string(swoole_redis_coro_ce, zobject, ZEND_STRL("errMsg"), context->errstr);
swoole_redis_coro_close(redis);
return false;
}
if (!(socket = swoole_redis_coro_get_socket(context)))
{
zend_update_property_long(swoole_redis_coro_ce, zobject, ZEND_STRL("errType"), SW_REDIS_ERR_OTHER);
zend_update_property_long(swoole_redis_coro_ce, zobject, ZEND_STRL("errCode"), sw_redis_convert_err(SW_REDIS_ERR_OTHER));
zend_update_property_string(swoole_redis_coro_ce, zobject, ZEND_STRL("errMsg"), "Can not found the connection");
swoole_redis_coro_close(redis);
return false;
}
swSetNonBlock(context->fd);
socket->set_timeout(redis->timeout, SW_TIMEOUT_RDWR);
redis->reconnected_count = 0;
zend_update_property_bool(swoole_redis_coro_ce, zobject, ZEND_STRL("connected"), 1);
zend_update_property_long(swoole_redis_coro_ce, zobject, ZEND_STRL("sock"), context->fd);
// auth and select db after connected
zval *zsetting = sw_zend_read_property_array(swoole_redis_coro_ce, redis->zobject, ZEND_STRL("setting"), 1);
HashTable *vht = Z_ARRVAL_P(zsetting);
if (php_swoole_array_get_value(vht, "password", ztmp))
{
zend::string passowrd(ztmp);
if (passowrd.len() > 0 && !redis_auth(redis, passowrd.val(), passowrd.len()))
{
swoole_redis_coro_close(redis);
return false;
}
}
if (php_swoole_array_get_value(vht, "database", ztmp))
{
zend_long db_number = zval_get_long(ztmp);
// default is 0, don't need select
if (db_number > 0 && !redis_select_db(redis, db_number))
{
swoole_redis_coro_close(redis);
return false;
}
}
return true;
}
static sw_inline bool swoole_redis_coro_keep_liveness(swRedisClient *redis)
{
Socket *socket = nullptr;
if (!redis->context || !(socket = swoole_redis_coro_get_socket(redis->context)) || !socket->check_liveness())
{
if (socket)
{
zend_update_property_long(swoole_redis_coro_ce, redis->zobject, ZEND_STRL("errType"), SW_REDIS_ERR_CLOSED);
zend_update_property_long(swoole_redis_coro_ce, redis->zobject, ZEND_STRL("errCode"), socket->errCode);
zend_update_property_string(swoole_redis_coro_ce, redis->zobject, ZEND_STRL("errMsg"), socket->errMsg);
}
swoole_redis_coro_close(redis);
for (; redis->reconnected_count < redis->reconnect_interval; redis->reconnected_count++)
{
if (swoole_redis_coro_connect(redis))
{
return true;
}
}
zend_update_property_long(swoole_redis_coro_ce, redis->zobject, ZEND_STRL("errType"), SW_REDIS_ERR_CLOSED);
// Notice: do not update errCode
zend_update_property_string(swoole_redis_coro_ce, redis->zobject, ZEND_STRL("errMsg"), "connection is not available");
return false;
}
return true;
}
static bool redis_auth(swRedisClient *redis, char *pw, size_t pw_len)
{
int i = 0;
size_t argvlen[2];
char *argv[2];
bool ret;
zval retval;
SW_REDIS_COMMAND_ARGV_FILL("AUTH", 4)
SW_REDIS_COMMAND_ARGV_FILL(pw, pw_len)
redis_request(redis, 2, argv, argvlen, &retval);
ret = Z_BVAL_P(&retval);
if (ret)
{
redis->session.auth = true;
}
return ret;
}
static bool redis_select_db(swRedisClient *redis, long db_number)
{
int i = 0;
size_t argvlen[2];
char *argv[2];
char str[32];
bool ret;
zval retval;
SW_REDIS_COMMAND_ARGV_FILL("SELECT", 6)
sprintf(str, "%ld", db_number);
SW_REDIS_COMMAND_ARGV_FILL(str, strlen(str))
redis_request(redis, 2, argv, argvlen, &retval);
ret = Z_BVAL_P(&retval);
if (ret)
{
redis->session.db_num = db_number;
}
return ret;
}
static void redis_request(swRedisClient *redis, int argc, char **argv, size_t *argvlen, zval *return_value, bool retry)
{
redisReply *reply = nullptr;
if (!swoole_redis_coro_keep_liveness(redis))
{
ZVAL_FALSE(return_value);
}
else
{
// must clear err before request
redis->context->err = 0;
zend_update_property_long(swoole_redis_coro_ce, redis->zobject, ZEND_STRL("errType"), 0);
zend_update_property_long(swoole_redis_coro_ce, redis->zobject, ZEND_STRL("errCode"), 0);
zend_update_property_string(swoole_redis_coro_ce, redis->zobject, ZEND_STRL("errMsg"), "");
if (redis->defer)
{
if (redisAppendCommandArgv(redis->context, argc, (const char **) argv, (const size_t *) argvlen) == REDIS_ERR)
{
goto _error;
}
else
{
ZVAL_TRUE(return_value);
}
}
else
{
reply = (redisReply *) redisCommandArgv(redis->context, argc, (const char **) argv, (const size_t *) argvlen);
if (reply == nullptr)
{
_error:
zend_update_property_long(swoole_redis_coro_ce, redis->zobject, ZEND_STRL("errType"), redis->context->err);
zend_update_property_long(swoole_redis_coro_ce, redis->zobject, ZEND_STRL("errCode"), sw_redis_convert_err(redis->context->err));
zend_update_property_string(swoole_redis_coro_ce, redis->zobject, ZEND_STRL("errMsg"), redis->context->errstr);
ZVAL_FALSE(return_value);
swoole_redis_coro_close(redis);
}
else
{
// Redis Cluster
if (reply->type == REDIS_REPLY_ERROR && (!strncmp(reply->str, "MOVED", 5) || !strcmp(reply->str, "ASK")))
{
char *p1, *p2;
// MOVED 1234 127.0.0.1:1234
p1 = strrchr(reply->str, ' ') + 1; // MOVED 1234 [p1]27.0.0.1:1234
p2 = strrchr(p1, ':'); // MOVED 1234 [p1]27.0.0.1[p2]1234
*p2 = '\0';
int port = atoi(p2 + 1);
zend_update_property_string(swoole_redis_coro_ce, redis->zobject, ZEND_STRL("host"), p1);
zend_update_property_long(swoole_redis_coro_ce, redis->zobject, ZEND_STRL("port"), port);
if (swoole_redis_coro_connect(redis) > 0)
{
freeReplyObject(reply);
redis_request(redis, argc, argv, argvlen, return_value, retry);
return;
}
else
{
ZVAL_FALSE(return_value);
}
}
// Normal Response
else
{
swoole_redis_coro_parse_result(redis, return_value, reply);
}
freeReplyObject(reply);
}
}
}
int i;
for (i = 0; i < argc; i++)
{
efree(argv[i]);
}
}
static sw_inline void sw_redis_command_empty(INTERNAL_FUNCTION_PARAMETERS, const char *cmd, int cmd_len)
{
SW_REDIS_COMMAND_CHECK
int i =0;
size_t argvlen[1];
char *argv[1];
SW_REDIS_COMMAND_ARGV_FILL(cmd, cmd_len)
redis_request(redis, 1, argv, argvlen, return_value);
}
static sw_inline void sw_redis_command_var_key(INTERNAL_FUNCTION_PARAMETERS, const char *cmd, int cmd_len, int min_argc, int has_timeout)
{
long timeout;
int argc = ZEND_NUM_ARGS();
if(argc < min_argc) {
RETURN_FALSE;
}
SW_REDIS_COMMAND_CHECK
SW_REDIS_COMMAND_ALLOC_ARGS_ARR
if(argc == 0 || zend_get_parameters_array(ht, argc, z_args) == FAILURE) {
efree(z_args);
RETURN_FALSE;
}
zend_bool single_array = 0;
if(has_timeout == 0) {
single_array = argc==1 && SW_REDIS_COMMAND_ARGS_TYPE(z_args[0])==IS_ARRAY;
} else {
single_array = argc==2 && SW_REDIS_COMMAND_ARGS_TYPE(z_args[0])==IS_ARRAY &&
SW_REDIS_COMMAND_ARGS_TYPE(z_args[1])==IS_LONG;
timeout = SW_REDIS_COMMAND_ARGS_LVAL(z_args[1]);
}
if (single_array)
{
argc = zend_hash_num_elements(SW_REDIS_COMMAND_ARGS_ARRVAL(z_args[0])) + 1;
}
else
{
argc++;
}
SW_REDIS_COMMAND_ALLOC_ARGV
int i = 0;
SW_REDIS_COMMAND_ARGV_FILL(cmd, cmd_len)
char buf[32];
size_t buf_len;
if (single_array)
{
zval *value;
SW_HASHTABLE_FOREACH_START(SW_REDIS_COMMAND_ARGS_ARRVAL(z_args[0]), value)
zend_string *convert_str = zval_get_string(value);
SW_REDIS_COMMAND_ARGV_FILL(ZSTR_VAL(convert_str), ZSTR_LEN(convert_str))
zend_string_release(convert_str);
SW_HASHTABLE_FOREACH_END();
if (has_timeout)
{
buf_len = sw_snprintf(buf, sizeof(buf), "%ld", timeout);
SW_REDIS_COMMAND_ARGV_FILL((char* )buf, buf_len);
}
}
else
{
if(has_timeout && SW_REDIS_COMMAND_ARGS_TYPE(z_args[argc-2]) != IS_LONG) {
zend_update_property_long(swoole_redis_coro_ce, redis->zobject, ZEND_STRL("errType"), SW_REDIS_ERR_OTHER);
zend_update_property_long(swoole_redis_coro_ce, redis->zobject, ZEND_STRL("errCode"), sw_redis_convert_err(SW_REDIS_ERR_OTHER));
zend_update_property_string(swoole_redis_coro_ce, redis->zobject, ZEND_STRL("errMsg"), "Timeout value must be a LONG");
efree(z_args);
RETURN_FALSE;
}
int j, tail;
tail = has_timeout ? argc - 2 : argc - 1;
for (j = 0; j < tail; ++j)
{
zend_string *convert_str = zval_get_string(&z_args[j]);
SW_REDIS_COMMAND_ARGV_FILL(ZSTR_VAL(convert_str), ZSTR_LEN(convert_str))
zend_string_release(convert_str);
}
if(has_timeout) {
buf_len = sw_snprintf(buf, sizeof(buf), ZEND_LONG_FMT, SW_REDIS_COMMAND_ARGS_LVAL(z_args[tail]));
SW_REDIS_COMMAND_ARGV_FILL((char*)buf, buf_len);
}
}
efree(z_args);
redis_request(redis, argc, argv, argvlen, return_value);
}
static inline void sw_redis_command_key(INTERNAL_FUNCTION_PARAMETERS, const char *cmd, int cmd_len)
{
char *key;
size_t key_len;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &key, &key_len) == FAILURE)
{
RETURN_FALSE;
}
SW_REDIS_COMMAND_CHECK
int i = 0;
size_t argvlen[2];
char *argv[2];
int argc = 2;
SW_REDIS_COMMAND_ARGV_FILL(cmd, cmd_len)
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
redis_request(redis, argc, argv, argvlen, return_value);
}
static sw_inline void sw_redis_command_key_var_val(INTERNAL_FUNCTION_PARAMETERS, const char *cmd, int cmd_len)
{
int argc = ZEND_NUM_ARGS();
// We at least need a key and one value
if (argc < 2)
{
RETURN_FALSE;
}
SW_REDIS_COMMAND_CHECK
// Make sure we at least have a key, and we can get other args
SW_REDIS_COMMAND_ALLOC_ARGS_ARR
if (zend_get_parameters_array(ht, argc, z_args) == FAILURE)
{
efree(z_args);
RETURN_FALSE;
}
int i = 0, j;
argc++;
SW_REDIS_COMMAND_ALLOC_ARGV
SW_REDIS_COMMAND_ARGV_FILL(cmd, cmd_len)
zend_string *convert_str = zval_get_string(&z_args[0]);
SW_REDIS_COMMAND_ARGV_FILL(ZSTR_VAL(convert_str), ZSTR_LEN(convert_str))
zend_string_release(convert_str);
for (j = 1; j < argc - 1; ++j)
{
SW_REDIS_COMMAND_ARGV_FILL_WITH_SERIALIZE(SW_REDIS_COMMAND_ARGS_REF(z_args[j]))
}
efree(z_args);
redis_request(redis, argc, argv, argvlen, return_value);
}
static sw_inline void sw_redis_command_key_long_val(INTERNAL_FUNCTION_PARAMETERS, const char *cmd, int cmd_len)
{
char *key;
size_t key_len;
long l_val;
zval *z_value;
if(zend_parse_parameters(ZEND_NUM_ARGS(), "slz", &key, &key_len, &l_val, &z_value) == FAILURE)
{
RETURN_FALSE;
}
SW_REDIS_COMMAND_CHECK
int i = 0;
size_t argvlen[4];
char *argv[4];
int argc = 4;
SW_REDIS_COMMAND_ARGV_FILL(cmd, cmd_len)
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
char str[32];
sprintf(str, "%ld", l_val);
SW_REDIS_COMMAND_ARGV_FILL(str, strlen(str))
SW_REDIS_COMMAND_ARGV_FILL_WITH_SERIALIZE(z_value)
redis_request(redis, argc, argv, argvlen, return_value);
}
static sw_inline void sw_redis_command_key_long_str(INTERNAL_FUNCTION_PARAMETERS, const char *cmd, int cmd_len)
{
char *key, *val;
size_t key_len, val_len;
long l_val;
if(zend_parse_parameters(ZEND_NUM_ARGS(), "sls", &key, &key_len, &l_val, &val, &val_len)==FAILURE)
{
return;
}
SW_REDIS_COMMAND_CHECK
int i = 0;
size_t argvlen[4];
char *argv[4];
int argc = 4;
SW_REDIS_COMMAND_ARGV_FILL(cmd, cmd_len)
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
char str[32];
sprintf(str, "%ld", l_val);
SW_REDIS_COMMAND_ARGV_FILL(str, strlen(str))
SW_REDIS_COMMAND_ARGV_FILL(val, val_len)
redis_request(redis, argc, argv, argvlen, return_value);
}
static sw_inline void sw_redis_command_key_long(INTERNAL_FUNCTION_PARAMETERS, const char *cmd, int cmd_len)
{
char *key;
size_t key_len;
long l_val;
if(zend_parse_parameters(ZEND_NUM_ARGS(), "sl", &key, &key_len, &l_val)==FAILURE)
{
return;
}
SW_REDIS_COMMAND_CHECK
int i = 0;
size_t argvlen[3];
char *argv[3];
int argc = 3;
SW_REDIS_COMMAND_ARGV_FILL(cmd, cmd_len)
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
char str[32];
sprintf(str, "%ld", l_val);
SW_REDIS_COMMAND_ARGV_FILL(str, strlen(str))
redis_request(redis, argc, argv, argvlen, return_value);
}
static sw_inline void sw_redis_command_key_long_long(INTERNAL_FUNCTION_PARAMETERS, const char *cmd, int cmd_len)
{
char *key;
size_t key_len;
long l1_val, l2_val;
if(zend_parse_parameters(ZEND_NUM_ARGS(), "sll", &key, &key_len, &l1_val, &l2_val)==FAILURE)
{
return;
}
SW_REDIS_COMMAND_CHECK
int i = 0;
size_t argvlen[4];
char *argv[4];
int argc = 4;
SW_REDIS_COMMAND_ARGV_FILL(cmd, cmd_len)
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
char str[32];
sprintf(str, "%ld", l1_val);
SW_REDIS_COMMAND_ARGV_FILL(str, strlen(str))
sprintf(str, "%ld", l2_val);
SW_REDIS_COMMAND_ARGV_FILL(str, strlen(str))
redis_request(redis, argc, argv, argvlen, return_value);
}
static sw_inline void sw_redis_command_key_dbl(INTERNAL_FUNCTION_PARAMETERS, const char *cmd, int cmd_len)
{
char *key;
size_t key_len;
double d_val;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sd", &key, &key_len, &d_val) == FAILURE)
{
RETURN_FALSE;
}
SW_REDIS_COMMAND_CHECK
int i =0;
size_t argvlen[3];
char *argv[3];
int argc = 3;
SW_REDIS_COMMAND_ARGV_FILL(cmd, cmd_len)
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
char str[32];
sprintf(str, "%f", d_val);
SW_REDIS_COMMAND_ARGV_FILL(str, strlen(str))
redis_request(redis, argc, argv, argvlen, return_value);
}
static sw_inline void sw_redis_command_key_key(INTERNAL_FUNCTION_PARAMETERS, const char *cmd, int cmd_len)
{
char *key1, *key2;
size_t key1_len, key2_len;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &key1, &key1_len, &key2, &key2_len) == FAILURE)
{
RETURN_FALSE;
}
SW_REDIS_COMMAND_CHECK
int i =0;
size_t argvlen[3];
char *argv[3];
int argc = 3;
SW_REDIS_COMMAND_ARGV_FILL(cmd, cmd_len)
SW_REDIS_COMMAND_ARGV_FILL(key1, key1_len)
SW_REDIS_COMMAND_ARGV_FILL(key2, key2_len)
redis_request(redis, argc, argv, argvlen, return_value);
}
static sw_inline void sw_redis_command_key_val(INTERNAL_FUNCTION_PARAMETERS, const char *cmd, int cmd_len)
{
char *key;
size_t key_len;
zval *z_value;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sz", &key, &key_len, &z_value) == FAILURE)
{
RETURN_FALSE;
}
SW_REDIS_COMMAND_CHECK
int i =0;
size_t argvlen[3];
char *argv[3];
SW_REDIS_COMMAND_ARGV_FILL(cmd, cmd_len)
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
SW_REDIS_COMMAND_ARGV_FILL_WITH_SERIALIZE(z_value)
redis_request(redis, 3, argv, argvlen, return_value);
}
static sw_inline void sw_redis_command_key_str(INTERNAL_FUNCTION_PARAMETERS, const char *cmd, int cmd_len)
{
char *key, *val;
size_t key_len, val_len;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &key, &key_len, &val, &val_len) == FAILURE)
{
RETURN_FALSE;
}
SW_REDIS_COMMAND_CHECK
int i =0;
size_t argvlen[3];
char *argv[3];
SW_REDIS_COMMAND_ARGV_FILL(cmd, cmd_len)
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
SW_REDIS_COMMAND_ARGV_FILL(val, val_len)
redis_request(redis, 3, argv, argvlen, return_value);
}
static sw_inline void sw_redis_command_key_str_str(INTERNAL_FUNCTION_PARAMETERS, const char *cmd, int cmd_len)
{
char *key, *val1, *val2;
size_t key_len, val1_len, val2_len;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sss", &key, &key_len, &val1, &val1_len, &val2, &val2_len) == FAILURE)
{
RETURN_FALSE;
}
SW_REDIS_COMMAND_CHECK
int i =0;
size_t argvlen[4];
char *argv[4];
SW_REDIS_COMMAND_ARGV_FILL(cmd, cmd_len)
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
SW_REDIS_COMMAND_ARGV_FILL(val1, val1_len)
SW_REDIS_COMMAND_ARGV_FILL(val2, val2_len)
redis_request(redis, 4, argv, argvlen, return_value);
}
static PHP_METHOD(swoole_redis_coro, __construct);
static PHP_METHOD(swoole_redis_coro, __destruct);
static PHP_METHOD(swoole_redis_coro, connect);
static PHP_METHOD(swoole_redis_coro, getAuth);
static PHP_METHOD(swoole_redis_coro, getDBNum);
static PHP_METHOD(swoole_redis_coro, getOptions);
static PHP_METHOD(swoole_redis_coro, setOptions);
static PHP_METHOD(swoole_redis_coro, getDefer);
static PHP_METHOD(swoole_redis_coro, setDefer);
static PHP_METHOD(swoole_redis_coro, recv);
static PHP_METHOD(swoole_redis_coro, request);
static PHP_METHOD(swoole_redis_coro, close);
/*---------------------Redis Command------------------------*/
static PHP_METHOD(swoole_redis_coro, set);
static PHP_METHOD(swoole_redis_coro, setBit);
static PHP_METHOD(swoole_redis_coro, setEx);
static PHP_METHOD(swoole_redis_coro, psetEx);
static PHP_METHOD(swoole_redis_coro, lSet);
static PHP_METHOD(swoole_redis_coro, get);
static PHP_METHOD(swoole_redis_coro, mGet);
static PHP_METHOD(swoole_redis_coro, del);
static PHP_METHOD(swoole_redis_coro, hDel);
static PHP_METHOD(swoole_redis_coro, hSet);
static PHP_METHOD(swoole_redis_coro, hMSet);
static PHP_METHOD(swoole_redis_coro, hSetNx);
static PHP_METHOD(swoole_redis_coro, mSet);
static PHP_METHOD(swoole_redis_coro, mSetNx);
static PHP_METHOD(swoole_redis_coro, getKeys);
static PHP_METHOD(swoole_redis_coro, exists);
static PHP_METHOD(swoole_redis_coro, type);
static PHP_METHOD(swoole_redis_coro, strLen);
static PHP_METHOD(swoole_redis_coro, lPop);
static PHP_METHOD(swoole_redis_coro, blPop);
static PHP_METHOD(swoole_redis_coro, rPop);
static PHP_METHOD(swoole_redis_coro, brPop);
static PHP_METHOD(swoole_redis_coro, bRPopLPush);
static PHP_METHOD(swoole_redis_coro, lSize);
static PHP_METHOD(swoole_redis_coro, sSize);
static PHP_METHOD(swoole_redis_coro, sPop);
static PHP_METHOD(swoole_redis_coro, sMembers);
static PHP_METHOD(swoole_redis_coro, sRandMember);
static PHP_METHOD(swoole_redis_coro, persist);
static PHP_METHOD(swoole_redis_coro, ttl);
static PHP_METHOD(swoole_redis_coro, pttl);
static PHP_METHOD(swoole_redis_coro, zCard);
static PHP_METHOD(swoole_redis_coro, hLen);
static PHP_METHOD(swoole_redis_coro, hKeys);
static PHP_METHOD(swoole_redis_coro, hVals);
static PHP_METHOD(swoole_redis_coro, hGetAll);
static PHP_METHOD(swoole_redis_coro, restore);
static PHP_METHOD(swoole_redis_coro, dump);
static PHP_METHOD(swoole_redis_coro, debug);
static PHP_METHOD(swoole_redis_coro, renameKey);
static PHP_METHOD(swoole_redis_coro, renameNx);
static PHP_METHOD(swoole_redis_coro, rpoplpush);
static PHP_METHOD(swoole_redis_coro, randomKey);
static PHP_METHOD(swoole_redis_coro, pfadd);
static PHP_METHOD(swoole_redis_coro, pfcount);
static PHP_METHOD(swoole_redis_coro, pfmerge);
static PHP_METHOD(swoole_redis_coro, ping);
static PHP_METHOD(swoole_redis_coro, auth);
static PHP_METHOD(swoole_redis_coro, unwatch);
static PHP_METHOD(swoole_redis_coro, watch);
static PHP_METHOD(swoole_redis_coro, save);
static PHP_METHOD(swoole_redis_coro, bgSave);
static PHP_METHOD(swoole_redis_coro, lastSave);
static PHP_METHOD(swoole_redis_coro, flushDB);
static PHP_METHOD(swoole_redis_coro, flushAll);
static PHP_METHOD(swoole_redis_coro, dbSize);
static PHP_METHOD(swoole_redis_coro, bgrewriteaof);
static PHP_METHOD(swoole_redis_coro, time);
static PHP_METHOD(swoole_redis_coro, role);
static PHP_METHOD(swoole_redis_coro, setRange);
static PHP_METHOD(swoole_redis_coro, setNx);
static PHP_METHOD(swoole_redis_coro, getSet);
static PHP_METHOD(swoole_redis_coro, append);
static PHP_METHOD(swoole_redis_coro, lPushx);
static PHP_METHOD(swoole_redis_coro, lPush);
static PHP_METHOD(swoole_redis_coro, rPush);
static PHP_METHOD(swoole_redis_coro, rPushx);
static PHP_METHOD(swoole_redis_coro, sContains);
static PHP_METHOD(swoole_redis_coro, zScore);
static PHP_METHOD(swoole_redis_coro, zRank);
static PHP_METHOD(swoole_redis_coro, zRevRank);
static PHP_METHOD(swoole_redis_coro, hGet);
static PHP_METHOD(swoole_redis_coro, hMGet);
static PHP_METHOD(swoole_redis_coro, hExists);
static PHP_METHOD(swoole_redis_coro, publish);
static PHP_METHOD(swoole_redis_coro, zIncrBy);
static PHP_METHOD(swoole_redis_coro, zAdd);
static PHP_METHOD(swoole_redis_coro, zDeleteRangeByScore);
static PHP_METHOD(swoole_redis_coro, zCount);
static PHP_METHOD(swoole_redis_coro, zRange);
static PHP_METHOD(swoole_redis_coro, zRevRange);
static PHP_METHOD(swoole_redis_coro, zRangeByScore);
static PHP_METHOD(swoole_redis_coro, zRevRangeByScore);
static PHP_METHOD(swoole_redis_coro, zRangeByLex);
static PHP_METHOD(swoole_redis_coro, zRevRangeByLex);
static PHP_METHOD(swoole_redis_coro, zInter);
static PHP_METHOD(swoole_redis_coro, zUnion);
static PHP_METHOD(swoole_redis_coro, incrBy);
static PHP_METHOD(swoole_redis_coro, hIncrBy);
static PHP_METHOD(swoole_redis_coro, incr);
static PHP_METHOD(swoole_redis_coro, decrBy);
static PHP_METHOD(swoole_redis_coro, decr);
static PHP_METHOD(swoole_redis_coro, getBit);
static PHP_METHOD(swoole_redis_coro, lGet);
static PHP_METHOD(swoole_redis_coro, lInsert);
static PHP_METHOD(swoole_redis_coro, setTimeout);
static PHP_METHOD(swoole_redis_coro, pexpire);
static PHP_METHOD(swoole_redis_coro, expireAt);
static PHP_METHOD(swoole_redis_coro, pexpireAt);
static PHP_METHOD(swoole_redis_coro, move);
static PHP_METHOD(swoole_redis_coro, select);
static PHP_METHOD(swoole_redis_coro, getRange);
static PHP_METHOD(swoole_redis_coro, listTrim);
static PHP_METHOD(swoole_redis_coro, lGetRange);
static PHP_METHOD(swoole_redis_coro, lRem);
static PHP_METHOD(swoole_redis_coro, zDeleteRangeByRank);
static PHP_METHOD(swoole_redis_coro, incrByFloat);
static PHP_METHOD(swoole_redis_coro, hIncrByFloat);
static PHP_METHOD(swoole_redis_coro, bitCount);
static PHP_METHOD(swoole_redis_coro, bitOp);
static PHP_METHOD(swoole_redis_coro, sAdd);
static PHP_METHOD(swoole_redis_coro, sMove);
static PHP_METHOD(swoole_redis_coro, sDiff);
static PHP_METHOD(swoole_redis_coro, sDiffStore);
static PHP_METHOD(swoole_redis_coro, sUnion);
static PHP_METHOD(swoole_redis_coro, sUnionStore);
static PHP_METHOD(swoole_redis_coro, sInter);
static PHP_METHOD(swoole_redis_coro, sInterStore);
static PHP_METHOD(swoole_redis_coro, sRemove);
static PHP_METHOD(swoole_redis_coro, zDelete);
static PHP_METHOD(swoole_redis_coro, subscribe);
static PHP_METHOD(swoole_redis_coro, pSubscribe);
static PHP_METHOD(swoole_redis_coro, unsubscribe);
static PHP_METHOD(swoole_redis_coro, pUnSubscribe);
static PHP_METHOD(swoole_redis_coro, multi);
static PHP_METHOD(swoole_redis_coro, exec);
static PHP_METHOD(swoole_redis_coro, eval);
static PHP_METHOD(swoole_redis_coro, evalSha);
static PHP_METHOD(swoole_redis_coro, script);
/*---------------------Redis Command End------------------------*/
static const zend_function_entry swoole_redis_coro_methods[] =
{
PHP_ME(swoole_redis_coro, __construct, arginfo_swoole_redis_coro_construct, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, __destruct, arginfo_swoole_redis_coro_void, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, connect, arginfo_swoole_redis_coro_connect, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, getAuth, arginfo_swoole_redis_coro_void, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, getDBNum, arginfo_swoole_redis_coro_void, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, getOptions, arginfo_swoole_redis_coro_void, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, setOptions, arginfo_swoole_redis_coro_setOptions, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, getDefer, arginfo_swoole_redis_coro_void, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, setDefer, arginfo_swoole_redis_coro_setDefer, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, recv, arginfo_swoole_redis_coro_void, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, request, arginfo_swoole_redis_coro_request, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, close, arginfo_swoole_redis_coro_close, ZEND_ACC_PUBLIC)
/*---------------------Redis Command------------------------*/
PHP_ME(swoole_redis_coro, set, arginfo_swoole_redis_coro_set, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, setBit, arginfo_swoole_redis_coro_setBit, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, setEx, arginfo_swoole_redis_coro_setex, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, psetEx, arginfo_swoole_redis_coro_psetex, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, lSet, arginfo_swoole_redis_coro_lSet, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, get, arginfo_swoole_redis_coro_get, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, mGet, arginfo_swoole_redis_coro_mget, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, del, arginfo_swoole_redis_coro_del, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, hDel, arginfo_swoole_redis_coro_hDel, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, hSet, arginfo_swoole_redis_coro_hSet, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, hMSet, arginfo_swoole_redis_coro_hMset, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, hSetNx, arginfo_swoole_redis_coro_hSetNx, ZEND_ACC_PUBLIC)
PHP_MALIAS(swoole_redis_coro, delete, del, arginfo_swoole_redis_coro_del, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, mSet, arginfo_swoole_redis_coro_mset, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, mSetNx, arginfo_swoole_redis_coro_msetnx, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, getKeys, arginfo_swoole_redis_coro_getKeys, ZEND_ACC_PUBLIC)
PHP_MALIAS(swoole_redis_coro, keys, getKeys, arginfo_swoole_redis_coro_getKeys, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, exists, arginfo_swoole_redis_coro_exists, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, type, arginfo_swoole_redis_coro_type, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, strLen, arginfo_swoole_redis_coro_strlen, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, lPop, arginfo_swoole_redis_coro_lPop, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, blPop, arginfo_swoole_redis_coro_blPop, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, rPop, arginfo_swoole_redis_coro_rPop, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, brPop, arginfo_swoole_redis_coro_brPop, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, bRPopLPush, arginfo_swoole_redis_coro_brpoplpush, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, lSize, arginfo_swoole_redis_coro_lSize, ZEND_ACC_PUBLIC)
PHP_MALIAS(swoole_redis_coro, lLen, lSize, arginfo_swoole_redis_coro_lLen, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, sSize, arginfo_swoole_redis_coro_sSize, ZEND_ACC_PUBLIC)
PHP_MALIAS(swoole_redis_coro, scard, sSize, arginfo_swoole_redis_coro_scard, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, sPop, arginfo_swoole_redis_coro_sPop, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, sMembers, arginfo_swoole_redis_coro_sMembers, ZEND_ACC_PUBLIC)
PHP_MALIAS(swoole_redis_coro, sGetMembers, sMembers, arginfo_swoole_redis_coro_key, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, sRandMember, arginfo_swoole_redis_coro_sRandMember, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, persist, arginfo_swoole_redis_coro_persist, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, ttl, arginfo_swoole_redis_coro_ttl, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, pttl, arginfo_swoole_redis_coro_pttl, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, zCard, arginfo_swoole_redis_coro_zCard, ZEND_ACC_PUBLIC)
PHP_MALIAS(swoole_redis_coro, zSize, zCard, arginfo_swoole_redis_coro_zSize, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, hLen, arginfo_swoole_redis_coro_hLen, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, hKeys, arginfo_swoole_redis_coro_hKeys, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, hVals, arginfo_swoole_redis_coro_hVals, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, hGetAll, arginfo_swoole_redis_coro_hGetAll, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, debug, arginfo_swoole_redis_coro_debug, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, restore, arginfo_swoole_redis_coro_restore, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, dump, arginfo_swoole_redis_coro_dump, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, renameKey, arginfo_swoole_redis_coro_renameKey, ZEND_ACC_PUBLIC)
PHP_MALIAS(swoole_redis_coro, rename, renameKey, arginfo_swoole_redis_coro_rename, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, renameNx, arginfo_swoole_redis_coro_renameNx, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, rpoplpush, arginfo_swoole_redis_coro_rpoplpush, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, randomKey, arginfo_swoole_redis_coro_randomKey, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, pfadd, arginfo_swoole_redis_coro_pfadd, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, pfcount, arginfo_swoole_redis_coro_pfcount, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, pfmerge, arginfo_swoole_redis_coro_pfmerge, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, ping, arginfo_swoole_redis_coro_ping, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, auth, arginfo_swoole_redis_coro_auth, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, unwatch, arginfo_swoole_redis_coro_unwatch, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, watch, arginfo_swoole_redis_coro_watch, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, save, arginfo_swoole_redis_coro_save, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, bgSave, arginfo_swoole_redis_coro_bgSave, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, lastSave, arginfo_swoole_redis_coro_lastSave, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, flushDB, arginfo_swoole_redis_coro_flushDB, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, flushAll, arginfo_swoole_redis_coro_flushAll, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, dbSize, arginfo_swoole_redis_coro_dbSize, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, bgrewriteaof, arginfo_swoole_redis_coro_bgrewriteaof, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, time, arginfo_swoole_redis_coro_time, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, role, arginfo_swoole_redis_coro_role, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, setRange, arginfo_swoole_redis_coro_setRange, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, setNx, arginfo_swoole_redis_coro_setnx, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, getSet, arginfo_swoole_redis_coro_getSet, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, append, arginfo_swoole_redis_coro_append, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, lPushx, arginfo_swoole_redis_coro_lPushx, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, lPush, arginfo_swoole_redis_coro_lPush, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, rPush, arginfo_swoole_redis_coro_rPush, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, rPushx, arginfo_swoole_redis_coro_rPushx, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, sContains, arginfo_swoole_redis_coro_sContains, ZEND_ACC_PUBLIC)
PHP_MALIAS(swoole_redis_coro, sismember, sContains, arginfo_swoole_redis_coro_key_value, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, zScore, arginfo_swoole_redis_coro_zScore, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, zRank, arginfo_swoole_redis_coro_zRank, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, zRevRank, arginfo_swoole_redis_coro_zRevRank, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, hGet, arginfo_swoole_redis_coro_hGet, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, hMGet, arginfo_swoole_redis_coro_hMget, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, hExists, arginfo_swoole_redis_coro_hExists, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, publish, arginfo_swoole_redis_coro_publish, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, zIncrBy, arginfo_swoole_redis_coro_zIncrBy, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, zAdd, arginfo_swoole_redis_coro_zAdd, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, zDeleteRangeByScore, arginfo_swoole_redis_coro_zDeleteRangeByScore, ZEND_ACC_PUBLIC)
PHP_MALIAS(swoole_redis_coro, zRemRangeByScore, zDeleteRangeByScore, arginfo_swoole_redis_coro_zRemRangeByScore, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, zCount, arginfo_swoole_redis_coro_zCount, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, zRange, arginfo_swoole_redis_coro_zRange, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, zRevRange, arginfo_swoole_redis_coro_zRevRange, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, zRangeByScore, arginfo_swoole_redis_coro_zRangeByScore, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, zRevRangeByScore, arginfo_swoole_redis_coro_zRevRangeByScore, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, zRangeByLex, arginfo_swoole_redis_coro_zRangeByLex, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, zRevRangeByLex, arginfo_swoole_redis_coro_zRevRangeByLex, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, zInter, arginfo_swoole_redis_coro_zInter, ZEND_ACC_PUBLIC)
PHP_MALIAS(swoole_redis_coro, zinterstore, zInter, arginfo_swoole_redis_coro_zinterstore, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, zUnion, arginfo_swoole_redis_coro_zUnion, ZEND_ACC_PUBLIC)
PHP_MALIAS(swoole_redis_coro, zunionstore, zUnion, arginfo_swoole_redis_coro_zunionstore, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, incrBy, arginfo_swoole_redis_coro_incrBy, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, hIncrBy, arginfo_swoole_redis_coro_hIncrBy, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, incr, arginfo_swoole_redis_coro_incr, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, decrBy, arginfo_swoole_redis_coro_decrBy, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, decr, arginfo_swoole_redis_coro_decr, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, getBit, arginfo_swoole_redis_coro_getBit, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, lInsert, arginfo_swoole_redis_coro_lInsert, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, lGet, arginfo_swoole_redis_coro_lGet, ZEND_ACC_PUBLIC)
PHP_MALIAS(swoole_redis_coro, lIndex, lGet, arginfo_swoole_redis_coro_key_long, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, setTimeout, arginfo_swoole_redis_coro_setTimeout, ZEND_ACC_PUBLIC)
PHP_MALIAS(swoole_redis_coro, expire, setTimeout, arginfo_swoole_redis_coro_key_long, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, pexpire, arginfo_swoole_redis_coro_pexpire, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, expireAt, arginfo_swoole_redis_coro_expireAt, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, pexpireAt, arginfo_swoole_redis_coro_pexpireAt, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, move, arginfo_swoole_redis_coro_move, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, select, arginfo_swoole_redis_coro_select, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, getRange, arginfo_swoole_redis_coro_getRange, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, listTrim, arginfo_swoole_redis_coro_listTrim, ZEND_ACC_PUBLIC)
PHP_MALIAS(swoole_redis_coro, ltrim, listTrim, arginfo_swoole_redis_coro_ltrim, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, lGetRange, arginfo_swoole_redis_coro_lGetRange, ZEND_ACC_PUBLIC)
PHP_MALIAS(swoole_redis_coro, lRange, lGetRange, arginfo_swoole_redis_coro_lrange, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, lRem, arginfo_swoole_redis_coro_lrem, ZEND_ACC_PUBLIC)
PHP_MALIAS(swoole_redis_coro, lRemove,lRem, arginfo_swoole_redis_coro_lRemove, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, zDeleteRangeByRank, arginfo_swoole_redis_coro_zDeleteRangeByRank, ZEND_ACC_PUBLIC)
PHP_MALIAS(swoole_redis_coro, zRemRangeByRank, zDeleteRangeByRank, arginfo_swoole_redis_coro_zRemRangeByRank, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, incrByFloat, arginfo_swoole_redis_coro_incrByFloat, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, hIncrByFloat, arginfo_swoole_redis_coro_hIncrByFloat, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, bitCount, arginfo_swoole_redis_coro_bitcount, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, bitOp, arginfo_swoole_redis_coro_bitop, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, sAdd, arginfo_swoole_redis_coro_sAdd, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, sMove, arginfo_swoole_redis_coro_sMove, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, sDiff, arginfo_swoole_redis_coro_sDiff, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, sDiffStore, arginfo_swoole_redis_coro_sDiffStore, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, sUnion, arginfo_swoole_redis_coro_sUnion, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, sUnionStore, arginfo_swoole_redis_coro_sUnionStore, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, sInter, arginfo_swoole_redis_coro_sInter, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, sInterStore, arginfo_swoole_redis_coro_sInterStore, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, sRemove, arginfo_swoole_redis_coro_sRemove, ZEND_ACC_PUBLIC)
PHP_MALIAS(swoole_redis_coro, srem, sRemove, arginfo_swoole_redis_coro_key_value, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, zDelete, arginfo_swoole_redis_coro_zDelete, ZEND_ACC_PUBLIC)
PHP_MALIAS(swoole_redis_coro, zRemove, zDelete, arginfo_swoole_redis_coro_zRemove, ZEND_ACC_PUBLIC)
PHP_MALIAS(swoole_redis_coro, zRem, zDelete, arginfo_swoole_redis_coro_zRem, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, pSubscribe, arginfo_swoole_redis_coro_psubscribe, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, subscribe, arginfo_swoole_redis_coro_subscribe, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, unsubscribe, arginfo_swoole_redis_coro_unsubscribe, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, pUnSubscribe, arginfo_swoole_redis_coro_punsubscribe, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, multi, arginfo_swoole_redis_coro_multi, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, exec, arginfo_swoole_redis_coro_exec, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, eval, arginfo_swoole_redis_coro_eval, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, evalSha, arginfo_swoole_redis_coro_evalsha, ZEND_ACC_PUBLIC)
PHP_ME(swoole_redis_coro, script, arginfo_swoole_redis_coro_script, ZEND_ACC_PUBLIC)
/*---------------------Redis Command End------------------------*/
PHP_FE_END
};
void swoole_redis_coro_init(int module_number)
{
SW_INIT_CLASS_ENTRY(swoole_redis_coro, "Swoole\\Coroutine\\Redis", NULL, "Co\\Redis", swoole_redis_coro_methods);
SW_SET_CLASS_SERIALIZABLE(swoole_redis_coro, zend_class_serialize_deny, zend_class_unserialize_deny);
SW_SET_CLASS_CLONEABLE(swoole_redis_coro, zend_class_clone_deny);
SW_SET_CLASS_UNSET_PROPERTY_HANDLER(swoole_redis_coro, zend_class_unset_property_deny);
zend_declare_property_string(swoole_redis_coro_ce, ZEND_STRL("host"), "", ZEND_ACC_PUBLIC);
zend_declare_property_long(swoole_redis_coro_ce, ZEND_STRL("port"), 0, ZEND_ACC_PUBLIC);
zend_declare_property_null(swoole_redis_coro_ce, ZEND_STRL("setting"), ZEND_ACC_PUBLIC);
zend_declare_property_long(swoole_redis_coro_ce, ZEND_STRL("sock"), -1, ZEND_ACC_PUBLIC);
zend_declare_property_bool(swoole_redis_coro_ce, ZEND_STRL("connected"), 0, ZEND_ACC_PUBLIC);
zend_declare_property_long(swoole_redis_coro_ce, ZEND_STRL("errType"), 0, ZEND_ACC_PUBLIC);
zend_declare_property_long(swoole_redis_coro_ce, ZEND_STRL("errCode"), 0, ZEND_ACC_PUBLIC);
zend_declare_property_string(swoole_redis_coro_ce, ZEND_STRL("errMsg"), "", ZEND_ACC_PUBLIC);
SW_REGISTER_LONG_CONSTANT("SWOOLE_REDIS_MODE_MULTI", SW_REDIS_MODE_MULTI);
SW_REGISTER_LONG_CONSTANT("SWOOLE_REDIS_MODE_PIPELINE", SW_REDIS_MODE_PIPELINE);
SW_REGISTER_LONG_CONSTANT("SWOOLE_REDIS_TYPE_NOT_FOUND", SW_REDIS_TYPE_NOT_FOUND);
SW_REGISTER_LONG_CONSTANT("SWOOLE_REDIS_TYPE_STRING", SW_REDIS_TYPE_STRING);
SW_REGISTER_LONG_CONSTANT("SWOOLE_REDIS_TYPE_SET", SW_REDIS_TYPE_SET);
SW_REGISTER_LONG_CONSTANT("SWOOLE_REDIS_TYPE_LIST", SW_REDIS_TYPE_LIST);
SW_REGISTER_LONG_CONSTANT("SWOOLE_REDIS_TYPE_ZSET", SW_REDIS_TYPE_ZSET);
SW_REGISTER_LONG_CONSTANT("SWOOLE_REDIS_TYPE_HASH", SW_REDIS_TYPE_HASH);
SW_REGISTER_LONG_CONSTANT("SWOOLE_REDIS_ERR_IO", SW_REDIS_ERR_IO);
SW_REGISTER_LONG_CONSTANT("SWOOLE_REDIS_ERR_OTHER", SW_REDIS_ERR_OTHER);
SW_REGISTER_LONG_CONSTANT("SWOOLE_REDIS_ERR_EOF", SW_REDIS_ERR_EOF);
SW_REGISTER_LONG_CONSTANT("SWOOLE_REDIS_ERR_PROTOCOL", SW_REDIS_ERR_PROTOCOL);
SW_REGISTER_LONG_CONSTANT("SWOOLE_REDIS_ERR_OOM", SW_REDIS_ERR_OOM);
SW_REGISTER_LONG_CONSTANT("SWOOLE_REDIS_ERR_CLOSED", SW_REDIS_ERR_CLOSED);
SW_REGISTER_LONG_CONSTANT("SWOOLE_REDIS_ERR_NOAUTH", SW_REDIS_ERR_NOAUTH);
SW_REGISTER_LONG_CONSTANT("SWOOLE_REDIS_ERR_ALLOC", SW_REDIS_ERR_ALLOC);
}
static void swoole_redis_coro_set_options(swRedisClient *redis, zval* zoptions, bool backward_compatibility = false)
{
zval *zsettings = sw_zend_read_property_array(swoole_redis_coro_ce, redis->zobject, ZEND_STRL("setting"), 1);
HashTable *vht = Z_ARRVAL_P(zoptions);
zval *ztmp;
php_array_merge(Z_ARRVAL_P(zsettings), vht);
if (php_swoole_array_get_value(vht, "connect_timeout", ztmp))
{
redis->connect_timeout = zval_get_double(ztmp);
if (redis->connect_timeout <= 0)
{
redis->connect_timeout = SW_TIMER_MAX_SEC;
}
}
if (php_swoole_array_get_value(vht, "timeout", ztmp))
{
redis->timeout = zval_get_double(ztmp);
if (backward_compatibility)
{
redis->connect_timeout = redis->timeout;
if (redis->connect_timeout <= 0)
{
redis->connect_timeout = SW_TIMER_MAX_SEC;
}
}
if (redis->context)
{
Socket *socket = swoole_redis_coro_get_socket(redis->context);
if (socket)
{
socket->set_timeout(redis->timeout, SW_TIMEOUT_RDWR);
}
}
}
if (php_swoole_array_get_value(vht, "serialize", ztmp))
{
redis->serialize = zval_is_true(ztmp);
}
if (php_swoole_array_get_value(vht, "reconnect", ztmp))
{
redis->reconnect_interval = (uint8_t) MIN(zval_get_long(ztmp), UINT8_MAX);
}
}
static PHP_METHOD(swoole_redis_coro, __construct)
{
swRedisClient *redis = (swRedisClient *) swoole_get_object(getThis());
zval *zsettings = sw_zend_read_property_array(swoole_redis_coro_ce, getThis(), ZEND_STRL("setting"), 1);
zval *zset = NULL;
ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 0, 1)
Z_PARAM_OPTIONAL
Z_PARAM_ARRAY(zset)
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
if (redis)
{
swoole_php_fatal_error(E_ERROR, "constructor can only be called once");
RETURN_FALSE;
}
redis = (swRedisClient *) emalloc(sizeof(swRedisClient));
bzero(redis, sizeof(swRedisClient));
redis->zobject = getThis();
sw_copy_to_stack(redis->zobject, redis->_zobject);
swoole_set_object(getThis(), redis);
redis->connect_timeout = Socket::default_connect_timeout;
redis->timeout = Socket::default_read_timeout;
redis->reconnect_interval = 1;
// settings init
add_assoc_double(zsettings, "connect_timeout", redis->connect_timeout);
add_assoc_double(zsettings, "timeout", redis->timeout);
add_assoc_bool(zsettings, "serialize", redis->serialize);
add_assoc_long(zsettings, "reconnect", redis->reconnect_interval);
// after connected
add_assoc_string(zsettings, "password", (char *) "");
add_assoc_long(zsettings, "database", 0);
if (zset)
{
swoole_redis_coro_set_options(redis, zset, true);
}
}
static PHP_METHOD(swoole_redis_coro, connect)
{
zval *zobject = getThis();
char *host = nullptr;
size_t host_len = 0;
zend_long port = 0;
zend_bool serialize = 0;
SW_REDIS_COMMAND_CHECK
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|lb", &host, &host_len, &port, &serialize) == FAILURE)
{
RETURN_FALSE;
}
zend_update_property_string(swoole_redis_coro_ce, zobject, ZEND_STRL("host"), host);
zend_update_property_long(swoole_redis_coro_ce, zobject, ZEND_STRL("port"), port);
redis->serialize = serialize;
if (swoole_redis_coro_connect(redis) > 0)
{
// clear the error code only when the developer manually tries to connect successfully
// if the kernel retries automatically, keep silent.
zend_update_property_long(swoole_redis_coro_ce, zobject, ZEND_STRL("errType"), 0);
zend_update_property_long(swoole_redis_coro_ce, zobject, ZEND_STRL("errCode"), 0);
zend_update_property_string(swoole_redis_coro_ce, zobject, ZEND_STRL("errMsg"), "");
RETURN_TRUE;
}
else
{
RETURN_FALSE;
}
}
static PHP_METHOD(swoole_redis_coro, getAuth)
{
swRedisClient *redis = swoole_get_redis_client(getThis());
if (redis->session.auth)
{
zval *ztmp = sw_zend_read_property_array(swoole_redis_coro_ce, getThis(), ZEND_STRL("setting"), 1);
if (php_swoole_array_get_value(Z_ARRVAL_P(ztmp), "password", ztmp))
{
RETURN_ZVAL(ztmp, 1, 0);
}
RETURN_EMPTY_STRING();
}
RETURN_FALSE;
}
static PHP_METHOD(swoole_redis_coro, getDBNum)
{
swRedisClient *redis = swoole_get_redis_client(getThis());
if (!redis->context)
{
RETURN_FALSE;
}
RETURN_LONG(redis->session.db_num);
}
static PHP_METHOD(swoole_redis_coro, getOptions)
{
RETURN_ZVAL(sw_zend_read_property_array(swoole_redis_coro_ce, getThis(), ZEND_STRL("setting"), 1), 1, 0);
}
static PHP_METHOD(swoole_redis_coro, setOptions)
{
swRedisClient *redis = swoole_get_redis_client(getThis());
zval *zoptions;
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_ARRAY(zoptions)
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
swoole_redis_coro_set_options(redis, zoptions);
RETURN_TRUE;
}
static PHP_METHOD(swoole_redis_coro, getDefer)
{
swRedisClient *redis = swoole_get_redis_client(getThis());
RETURN_BOOL(redis->defer);
}
static PHP_METHOD(swoole_redis_coro, setDefer)
{
swRedisClient *redis = swoole_get_redis_client(getThis());
zend_bool defer = 1;
if (redis->session.subscribe)
{
swoole_php_fatal_error(E_WARNING, "you should not use setDefer after subscribe");
RETURN_FALSE;
}
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &defer) == FAILURE)
{
RETURN_FALSE;
}
redis->defer = defer;
RETURN_TRUE;
}
static PHP_METHOD(swoole_redis_coro, recv)
{
SW_REDIS_COMMAND_CHECK
if (UNEXPECTED(!redis->context))
{
RETURN_FALSE;
}
if (UNEXPECTED(!redis->defer && !redis->session.subscribe))
{
swoole_php_fatal_error(E_WARNING, "you should not use recv without defer or subscribe");
RETURN_FALSE;
}
redisReply *reply;
_recv:
if (redisGetReply(redis->context, (void**) &reply) == REDIS_OK)
{
swoole_redis_coro_parse_result(redis, return_value, reply);
freeReplyObject(reply);
if (redis->session.subscribe)
{
zval *ztype;
if (Z_TYPE_P(return_value) != IS_ARRAY)
{
zval_ptr_dtor(return_value);
goto _error;
}
ztype = zend_hash_index_find(Z_ARRVAL_P(return_value), 0);
if (Z_TYPE_P(ztype) == IS_STRING)
{
char *type = Z_STRVAL_P(ztype);
if (!strcmp(type, "unsubscribe") || !strcmp(type, "punsubscribe"))
{
zval *znum = zend_hash_index_find(Z_ARRVAL_P(return_value), 2);
if (Z_LVAL_P(znum) == 0)
{
redis->session.subscribe = false;
}
return;
}
else if (!strcmp(type, "message") || !strcmp(type, "pmessage")
|| !strcmp(type, "subscribe") || !strcmp(type, "psubscribe"))
{
return;
}
}
zval_ptr_dtor(return_value);
goto _recv;
}
}
else
{
_error:
zend_update_property_long(swoole_redis_coro_ce, redis->zobject, ZEND_STRL("errType"), redis->context->err);
zend_update_property_long(swoole_redis_coro_ce, redis->zobject, ZEND_STRL("errCode"), sw_redis_convert_err(redis->context->err));
zend_update_property_string(swoole_redis_coro_ce, redis->zobject, ZEND_STRL("errMsg"), redis->context->errstr);
swoole_redis_coro_close(redis);
RETURN_FALSE;
}
}
static PHP_METHOD(swoole_redis_coro, close)
{
swRedisClient *redis = swoole_get_redis_client(getThis());
RETURN_BOOL(swoole_redis_coro_close(redis));
}
static PHP_METHOD(swoole_redis_coro, __destruct)
{
SW_PREVENT_USER_DESTRUCT();
swRedisClient *redis = (swRedisClient *) swoole_get_object(getThis());
if (!redis)
{
return;
}
if (redis->context)
{
swoole_redis_coro_close(redis);
}
swoole_set_object(getThis(), NULL);
efree(redis);
}
static PHP_METHOD(swoole_redis_coro, set)
{
char *key, *exp_type = NULL, *set_type = NULL;
size_t key_len, argc = 3;
zval *z_value, *z_opts = NULL;
zend_long expire = -1;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sz|z", &key, &key_len, &z_value, &z_opts) == FAILURE)
{
RETURN_FALSE;
}
SW_REDIS_COMMAND_CHECK
if (z_opts && Z_TYPE_P(z_opts) != IS_LONG && Z_TYPE_P(z_opts) != IS_ARRAY && Z_TYPE_P(z_opts) != IS_NULL)
{
RETURN_FALSE;
}
if (z_opts && Z_TYPE_P(z_opts) == IS_ARRAY)
{
HashTable *kt = Z_ARRVAL_P(z_opts);
zend_string *zkey;
zend_ulong idx;
zval *v;
/* Iterate our option array */
ZEND_HASH_FOREACH_KEY_VAL(kt, idx, zkey, v)
{
/* Detect PX or EX argument and validate timeout */
if (!exp_type && zkey && IS_EX_PX_ARG(ZSTR_VAL(zkey)))
{
/* Set expire type */
exp_type = ZSTR_VAL(zkey);
/* Try to extract timeout */
if (Z_TYPE_P(v) == IS_LONG)
{
expire = Z_LVAL_P(v);
}
else if (Z_TYPE_P(v) == IS_STRING)
{
expire = atol(Z_STRVAL_P(v));
}
/* Expiry can't be set < 1 */
if (expire < 1)
{
RETURN_FALSE;
}
argc += 2;
}
else if (!set_type && Z_TYPE_P(v) == IS_STRING && IS_NX_XX_ARG(Z_STRVAL_P(v)))
{
argc += 1;
set_type = Z_STRVAL_P(v);
}
(void) idx;
}
ZEND_HASH_FOREACH_END();
}
else if (z_opts && Z_TYPE_P(z_opts) == IS_LONG)
{
/* Grab expiry and fail if it's < 1 */
expire = Z_LVAL_P(z_opts);
/* Expiry can't be set < 1 */
if (expire < 1)
{
RETURN_FALSE;
}
argc += 1;
}
SW_REDIS_COMMAND_ALLOC_ARGV
int i = 0;
if (exp_type || set_type)
{
SW_REDIS_COMMAND_ARGV_FILL("SET", 3)
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
SW_REDIS_COMMAND_ARGV_FILL_WITH_SERIALIZE(z_value)
if (set_type)
{
SW_REDIS_COMMAND_ARGV_FILL(set_type, (size_t ) strlen(set_type))
}
if (exp_type)
{
SW_REDIS_COMMAND_ARGV_FILL(exp_type, (size_t ) strlen(exp_type))
char str[32];
sprintf(str, ZEND_LONG_FMT, expire);
SW_REDIS_COMMAND_ARGV_FILL(str, (size_t ) strlen(str))
}
}
else if (expire > 0)
{
SW_REDIS_COMMAND_ARGV_FILL("SETEX", 5)
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
char str[32];
sprintf(str, ZEND_LONG_FMT, expire);
SW_REDIS_COMMAND_ARGV_FILL(str, (size_t ) strlen(str))
SW_REDIS_COMMAND_ARGV_FILL_WITH_SERIALIZE(z_value)
}
else
{
SW_REDIS_COMMAND_ARGV_FILL("SET", 3)
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
SW_REDIS_COMMAND_ARGV_FILL_WITH_SERIALIZE(z_value)
}
redis_request(redis, argc, argv, argvlen, return_value);
SW_REDIS_COMMAND_FREE_ARGV
}
static PHP_METHOD(swoole_redis_coro, setBit)
{
char *key;
size_t key_len;
long offset;
zend_bool val;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "slb", &key, &key_len, &offset, &val) == FAILURE)
{
return;
}
// Validate our offset
if(offset < SW_BITOP_MIN_OFFSET || offset >SW_BITOP_MAX_OFFSET) {
zend_update_property_long(swoole_redis_coro_ce, getThis(), ZEND_STRL("errType"), SW_REDIS_ERR_OTHER);
zend_update_property_long(swoole_redis_coro_ce, getThis(), ZEND_STRL("errCode"), sw_redis_convert_err(SW_REDIS_ERR_OTHER));
zend_update_property_string(swoole_redis_coro_ce, getThis(), ZEND_STRL("errMsg"), "Invalid OFFSET for bitop command (must be between 0-2^32-1)");
RETURN_FALSE;
}
SW_REDIS_COMMAND_CHECK
int i = 0;
size_t argvlen[4];
char *argv[4];
SW_REDIS_COMMAND_ARGV_FILL("SETBIT", 6)
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
char str[32];
sprintf(str, "%ld", offset);
SW_REDIS_COMMAND_ARGV_FILL(str, strlen(str))
SW_REDIS_COMMAND_ARGV_FILL(val ? "1" : "0", 1)
redis_request(redis, 4, argv, argvlen, return_value);
}
static PHP_METHOD(swoole_redis_coro, setEx)
{
sw_redis_command_key_long_val(INTERNAL_FUNCTION_PARAM_PASSTHRU, "SETEX", 5);
}
static PHP_METHOD(swoole_redis_coro, psetEx)
{
sw_redis_command_key_long_val(INTERNAL_FUNCTION_PARAM_PASSTHRU, "PSETEX", 6);
}
static PHP_METHOD(swoole_redis_coro, lSet)
{
sw_redis_command_key_long_val(INTERNAL_FUNCTION_PARAM_PASSTHRU, "LSET", 4);
}
static PHP_METHOD(swoole_redis_coro, restore)
{
sw_redis_command_key_long_val(INTERNAL_FUNCTION_PARAM_PASSTHRU, "RESTORE", 7);
}
static PHP_METHOD(swoole_redis_coro, dump)
{
sw_redis_command_key(INTERNAL_FUNCTION_PARAM_PASSTHRU, "DUMP", 4);
}
static PHP_METHOD(swoole_redis_coro, debug)
{
sw_redis_command_key(INTERNAL_FUNCTION_PARAM_PASSTHRU, "DEBUG", 5);
}
static PHP_METHOD(swoole_redis_coro, get)
{
sw_redis_command_key(INTERNAL_FUNCTION_PARAM_PASSTHRU, "GET", 3);
}
static PHP_METHOD(swoole_redis_coro, mGet)
{
zval *z_args;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &z_args) == FAILURE)
{
RETURN_FALSE;
}
int argc;
argc = zend_hash_num_elements(Z_ARRVAL_P(z_args));
if (argc == 0)
{
RETURN_FALSE;
}
SW_REDIS_COMMAND_CHECK
argc++;
SW_REDIS_COMMAND_ALLOC_ARGV
int i = 0;
zval *value;
SW_REDIS_COMMAND_ARGV_FILL("MGET", 4)
SW_HASHTABLE_FOREACH_START(Z_ARRVAL_P(z_args), value)
zend_string *convert_str = zval_get_string(value);
SW_REDIS_COMMAND_ARGV_FILL(ZSTR_VAL(convert_str), ZSTR_LEN(convert_str))
zend_string_release(convert_str);
SW_HASHTABLE_FOREACH_END();
redis_request(redis, argc, argv, argvlen, return_value);
SW_REDIS_COMMAND_FREE_ARGV
}
static PHP_METHOD(swoole_redis_coro, hSet)
{
char *key, *field;
size_t key_len, field_len;
zval *z_val;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ssz", &key, &key_len, &field, &field_len, &z_val) == FAILURE)
{
return;
}
SW_REDIS_COMMAND_CHECK
int i = 0;
size_t argvlen[4];
char *argv[4];
SW_REDIS_COMMAND_ARGV_FILL("HSET", 4)
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
SW_REDIS_COMMAND_ARGV_FILL(field, field_len)
SW_REDIS_COMMAND_ARGV_FILL_WITH_SERIALIZE(z_val)
redis_request(redis, 4, argv, argvlen, return_value);
}
static PHP_METHOD(swoole_redis_coro, hMSet)
{
char *key;
size_t key_len, argc;
zval *z_arr;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sa", &key, &key_len, &z_arr) == FAILURE)
{
return;
}
if ((argc = zend_hash_num_elements(Z_ARRVAL_P(z_arr))) == 0)
{
RETURN_FALSE;
}
SW_REDIS_COMMAND_CHECK
int i = 0;
argc = argc * 2 + 2;
zval *value;
char buf[32];
SW_REDIS_COMMAND_ALLOC_ARGV
SW_REDIS_COMMAND_ARGV_FILL("HMSET", 5)
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
zend_ulong idx;
zend_string *_key;
ZEND_HASH_FOREACH_KEY_VAL_IND(Z_ARRVAL_P(z_arr), idx, _key, value) {
if (_key == NULL)
{
key_len = sw_snprintf(buf, sizeof(buf), "%ld", (long) idx);
key = (char*) buf;
}
else
{
key_len = ZSTR_LEN(_key);
key = ZSTR_VAL(_key);
}
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
SW_REDIS_COMMAND_ARGV_FILL_WITH_SERIALIZE(value)
} ZEND_HASH_FOREACH_END();
redis_request(redis, argc, argv, argvlen, return_value);
SW_REDIS_COMMAND_FREE_ARGV
}
static PHP_METHOD(swoole_redis_coro, hSetNx)
{
char *key, *field;
size_t key_len, field_len;
zval *z_val;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ssz", &key, &key_len, &field, &field_len, &z_val) == FAILURE)
{
return;
}
SW_REDIS_COMMAND_CHECK
int i = 0;
size_t argvlen[4];
char *argv[4];
convert_to_string(z_val);
SW_REDIS_COMMAND_ARGV_FILL("HSETNX", 6)
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
SW_REDIS_COMMAND_ARGV_FILL(field, field_len)
SW_REDIS_COMMAND_ARGV_FILL(Z_STRVAL_P(z_val), Z_STRLEN_P(z_val))
redis_request(redis, 4, argv, argvlen, return_value);
}
static PHP_METHOD(swoole_redis_coro, hDel)
{
int argc = ZEND_NUM_ARGS();
SW_REDIS_COMMAND_CHECK
SW_REDIS_COMMAND_ALLOC_ARGS_ARR
if(argc < 2 || zend_get_parameters_array(ht, argc, z_args) == FAILURE) {
efree(z_args);
RETURN_FALSE;
}
argc++;
int i = 0, j;
SW_REDIS_COMMAND_ALLOC_ARGV
SW_REDIS_COMMAND_ARGV_FILL("HDEL", 4)
for (j = 0; j < argc-1; ++j)
{
zend_string *convert_str = zval_get_string(&z_args[j]);
SW_REDIS_COMMAND_ARGV_FILL(ZSTR_VAL(convert_str), ZSTR_LEN(convert_str))
zend_string_release(convert_str);
}
efree(z_args);
redis_request(redis, argc, argv, argvlen, return_value);
SW_REDIS_COMMAND_FREE_ARGV
}
static PHP_METHOD(swoole_redis_coro, watch)
{
sw_redis_command_var_key(INTERNAL_FUNCTION_PARAM_PASSTHRU, "WATCH", 5, 1, 0);
}
static PHP_METHOD(swoole_redis_coro, del)
{
sw_redis_command_var_key(INTERNAL_FUNCTION_PARAM_PASSTHRU, "DEL", 3, 1, 0);
}
static PHP_METHOD(swoole_redis_coro, sDiff)
{
sw_redis_command_var_key(INTERNAL_FUNCTION_PARAM_PASSTHRU, "SDIFF", 5, 1, 0);
}
static PHP_METHOD(swoole_redis_coro, sDiffStore)
{
sw_redis_command_var_key(INTERNAL_FUNCTION_PARAM_PASSTHRU, "SDIFFSTORE", 10, 1, 0);
}
static PHP_METHOD(swoole_redis_coro, sUnion)
{
sw_redis_command_var_key(INTERNAL_FUNCTION_PARAM_PASSTHRU, "SUNION", 6, 1, 0);
}
static PHP_METHOD(swoole_redis_coro, sUnionStore)
{
sw_redis_command_var_key(INTERNAL_FUNCTION_PARAM_PASSTHRU, "SUNIONSTORE", 11, 1, 0);
}
static PHP_METHOD(swoole_redis_coro, sInter)
{
sw_redis_command_var_key(INTERNAL_FUNCTION_PARAM_PASSTHRU, "SINTER", 6, 1, 0);
}
static PHP_METHOD(swoole_redis_coro, sInterStore)
{
sw_redis_command_var_key(INTERNAL_FUNCTION_PARAM_PASSTHRU, "SINTERSTORE", 11, 1, 0);
}
static PHP_METHOD(swoole_redis_coro, mSet)
{
zval *z_args;
if(zend_parse_parameters(ZEND_NUM_ARGS(), "a", &z_args) == FAILURE)
{
RETURN_FALSE;
}
int argc;
argc = zend_hash_num_elements(Z_ARRVAL_P(z_args));
if (argc == 0)
{
RETURN_FALSE;
}
SW_REDIS_COMMAND_CHECK
argc *= 2;
argc++;
SW_REDIS_COMMAND_ALLOC_ARGV
int i = 0;
SW_REDIS_COMMAND_ARGV_FILL("MSET", 4)
zval *value;
char buf[32];
char *key;
uint32_t key_len;
zend_ulong idx;
zend_string *_key;
ZEND_HASH_FOREACH_KEY_VAL_IND(Z_ARRVAL_P(z_args), idx, _key, value) {
if (_key == NULL)
{
key_len = sw_snprintf(buf, sizeof(buf), "%ld", (long) idx);
key = (char*) buf;
}
else
{
key_len = ZSTR_LEN(_key);
key = ZSTR_VAL(_key);
}
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
SW_REDIS_COMMAND_ARGV_FILL_WITH_SERIALIZE(value)
} ZEND_HASH_FOREACH_END();
redis_request(redis, argc, argv, argvlen, return_value);
SW_REDIS_COMMAND_FREE_ARGV
}
static PHP_METHOD(swoole_redis_coro, mSetNx)
{
zval *z_args;
if(zend_parse_parameters(ZEND_NUM_ARGS(), "a", &z_args)==FAILURE)
{
return;
}
int argc;
argc = zend_hash_num_elements(Z_ARRVAL_P(z_args));
if (argc == 0)
{
RETURN_FALSE;
}
SW_REDIS_COMMAND_CHECK
argc *= 2;
argc++;
SW_REDIS_COMMAND_ALLOC_ARGV
int i = 0;
SW_REDIS_COMMAND_ARGV_FILL("MSETNX", 6)
zval *value;
char buf[32];
char *key;
uint32_t key_len;
zend_ulong idx;
zend_string *_key;
ZEND_HASH_FOREACH_KEY_VAL_IND(Z_ARRVAL_P(z_args), idx, _key, value) {
if (_key == NULL) {
key_len = sw_snprintf(buf, sizeof(buf), "%ld", (long)idx);
key = (char*)buf;
} else {
key_len = ZSTR_LEN(_key);
key = ZSTR_VAL(_key);
}
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
SW_REDIS_COMMAND_ARGV_FILL_WITH_SERIALIZE(value)
} ZEND_HASH_FOREACH_END();
redis_request(redis, argc, argv, argvlen, return_value);
SW_REDIS_COMMAND_FREE_ARGV
}
static PHP_METHOD(swoole_redis_coro, getKeys)
{
sw_redis_command_key(INTERNAL_FUNCTION_PARAM_PASSTHRU, "KEYS", 4);
}
static PHP_METHOD(swoole_redis_coro, exists)
{
sw_redis_command_key(INTERNAL_FUNCTION_PARAM_PASSTHRU, "EXISTS", 6);
}
static PHP_METHOD(swoole_redis_coro, type)
{
sw_redis_command_key(INTERNAL_FUNCTION_PARAM_PASSTHRU, "TYPE", 4);
}
static PHP_METHOD(swoole_redis_coro, strLen)
{
sw_redis_command_key(INTERNAL_FUNCTION_PARAM_PASSTHRU, "STRLEN", 6);
}
static PHP_METHOD(swoole_redis_coro, lPop)
{
sw_redis_command_key(INTERNAL_FUNCTION_PARAM_PASSTHRU, "LPOP", 4);
}
static PHP_METHOD(swoole_redis_coro, bRPopLPush)
{
char *key1, *key2;
size_t key1_len, key2_len;
long timeout;
if(zend_parse_parameters(ZEND_NUM_ARGS(), "ssl", &key1, &key1_len,
&key2, &key2_len, &timeout) == FAILURE)
{
return;
}
SW_REDIS_COMMAND_CHECK
int argc, i = 0;
argc = timeout < 0 ? 3 : 4;
SW_REDIS_COMMAND_ALLOC_ARGV
if (timeout < 0)
{
SW_REDIS_COMMAND_ARGV_FILL("RPOPLPUSH", 9)
SW_REDIS_COMMAND_ARGV_FILL(key1, key1_len)
SW_REDIS_COMMAND_ARGV_FILL(key2, key2_len)
}
else
{
SW_REDIS_COMMAND_ARGV_FILL("BRPOPLPUSH", 10)
SW_REDIS_COMMAND_ARGV_FILL(key1, key1_len)
SW_REDIS_COMMAND_ARGV_FILL(key2, key2_len)
char str[32];
sprintf(str, "%ld", timeout);
SW_REDIS_COMMAND_ARGV_FILL(str, strlen(str))
}
redis_request(redis, argc, argv, argvlen, return_value);
SW_REDIS_COMMAND_FREE_ARGV
}
static PHP_METHOD(swoole_redis_coro, blPop)
{
int argc = ZEND_NUM_ARGS();
SW_REDIS_COMMAND_CHECK
SW_REDIS_COMMAND_ALLOC_ARGS_ARR
if(zend_get_parameters_array(ht, argc, z_args) == FAILURE || argc < 1)
{
efree(z_args);
return;
}
zend_bool single_array = 0;
if (argc == 2 && SW_REDIS_COMMAND_ARGS_TYPE(z_args[0]) == IS_ARRAY)
{
argc = zend_hash_num_elements(SW_REDIS_COMMAND_ARGS_ARRVAL(z_args[0])) + 2;
single_array = 1;
}
else
{
argc += 1;
}
int i = 0;
SW_REDIS_COMMAND_ALLOC_ARGV
SW_REDIS_COMMAND_ARGV_FILL("BLPOP", 5)
if (single_array)
{
zval *value;
SW_HASHTABLE_FOREACH_START(SW_REDIS_COMMAND_ARGS_ARRVAL(z_args[0]), value)
zend_string *convert_str = zval_get_string(value);
SW_REDIS_COMMAND_ARGV_FILL(ZSTR_VAL(convert_str), ZSTR_LEN(convert_str))
zend_string_release(convert_str);
SW_HASHTABLE_FOREACH_END();
zend_string *convert_str = zval_get_string(&z_args[1]);
SW_REDIS_COMMAND_ARGV_FILL(ZSTR_VAL(convert_str), ZSTR_LEN(convert_str))
zend_string_release(convert_str);
}
else
{
int j;
for (j = 0; j < argc - 1; ++j)
{
zend_string *convert_str = zval_get_string(&z_args[j]);
SW_REDIS_COMMAND_ARGV_FILL(ZSTR_VAL(convert_str), ZSTR_LEN(convert_str))
zend_string_release(convert_str);
}
}
efree(z_args);
redis_request(redis, argc, argv, argvlen, return_value);
SW_REDIS_COMMAND_FREE_ARGV
}
static PHP_METHOD(swoole_redis_coro, brPop)
{
int argc = ZEND_NUM_ARGS();
SW_REDIS_COMMAND_CHECK
SW_REDIS_COMMAND_ALLOC_ARGS_ARR
if(zend_get_parameters_array(ht, argc, z_args) == FAILURE || argc < 1)
{
efree(z_args);
return;
}
zend_bool single_array = 0;
if (argc == 2 && SW_REDIS_COMMAND_ARGS_TYPE(z_args[0]) == IS_ARRAY)
{
argc = zend_hash_num_elements(SW_REDIS_COMMAND_ARGS_ARRVAL(z_args[0])) + 2;
single_array = 1;
}
else
{
argc += 1;
}
int i = 0;
SW_REDIS_COMMAND_ALLOC_ARGV
SW_REDIS_COMMAND_ARGV_FILL("BRPOP", 5)
if (single_array)
{
zval *value;
SW_HASHTABLE_FOREACH_START(SW_REDIS_COMMAND_ARGS_ARRVAL(z_args[0]), value)
zend_string *convert_str = zval_get_string(value);
SW_REDIS_COMMAND_ARGV_FILL(ZSTR_VAL(convert_str), ZSTR_LEN(convert_str))
zend_string_release(convert_str);
SW_HASHTABLE_FOREACH_END();
zend_string *convert_str = zval_get_string(&z_args[1]);
SW_REDIS_COMMAND_ARGV_FILL(ZSTR_VAL(convert_str), ZSTR_LEN(convert_str))
zend_string_release(convert_str);
}
else
{
int j;
for (j = 0; j < argc - 1; ++j)
{
zend_string *convert_str = zval_get_string(&z_args[j]);
SW_REDIS_COMMAND_ARGV_FILL(ZSTR_VAL(convert_str), ZSTR_LEN(convert_str))
zend_string_release(convert_str);
}
}
efree(z_args);
redis_request(redis, argc, argv, argvlen, return_value);
SW_REDIS_COMMAND_FREE_ARGV
}
static PHP_METHOD(swoole_redis_coro, rPop)
{
sw_redis_command_key(INTERNAL_FUNCTION_PARAM_PASSTHRU, "RPOP", 4);
}
static PHP_METHOD(swoole_redis_coro, lSize)
{
sw_redis_command_key(INTERNAL_FUNCTION_PARAM_PASSTHRU, "LLEN", 4);
}
static PHP_METHOD(swoole_redis_coro, sSize)
{
sw_redis_command_key(INTERNAL_FUNCTION_PARAM_PASSTHRU, "SCARD", 5);
}
static PHP_METHOD(swoole_redis_coro, sPop)
{
sw_redis_command_key(INTERNAL_FUNCTION_PARAM_PASSTHRU, "SPOP", 4);
}
static PHP_METHOD(swoole_redis_coro, sMembers)
{
sw_redis_command_key(INTERNAL_FUNCTION_PARAM_PASSTHRU, "SMEMBERS", 8);
}
static PHP_METHOD(swoole_redis_coro, sRandMember)
{
char *key;
size_t key_len;
zend_long count = 0;
if(zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &key, &key_len, &count) == FAILURE)
{
RETURN_FALSE;
}
SW_REDIS_COMMAND_CHECK
int i = 0, argc, buf_len;
char buf[32];
argc = ZEND_NUM_ARGS() == 2 ? 3 : 2;
SW_REDIS_COMMAND_ALLOC_ARGV
SW_REDIS_COMMAND_ARGV_FILL("SRANDMEMBER", 11);
SW_REDIS_COMMAND_ARGV_FILL(key, key_len);
if (argc == 3)
{
buf_len = sw_snprintf(buf, sizeof(buf), "%ld", count);
SW_REDIS_COMMAND_ARGV_FILL((char *)buf, buf_len);
}
redis_request(redis, argc, argv, argvlen, return_value);;
SW_REDIS_COMMAND_FREE_ARGV
}
static PHP_METHOD(swoole_redis_coro, persist)
{
sw_redis_command_key(INTERNAL_FUNCTION_PARAM_PASSTHRU, "PERSIST", 7);
}
static PHP_METHOD(swoole_redis_coro, ttl)
{
sw_redis_command_key(INTERNAL_FUNCTION_PARAM_PASSTHRU, "TTL", 3);
}
static PHP_METHOD(swoole_redis_coro, pttl)
{
sw_redis_command_key(INTERNAL_FUNCTION_PARAM_PASSTHRU, "PTTL", 4);
}
static PHP_METHOD(swoole_redis_coro, zCard)
{
sw_redis_command_key(INTERNAL_FUNCTION_PARAM_PASSTHRU, "ZCARD", 5);
}
static PHP_METHOD(swoole_redis_coro, hLen)
{
sw_redis_command_key(INTERNAL_FUNCTION_PARAM_PASSTHRU, "HLEN", 4);
}
static PHP_METHOD(swoole_redis_coro, hKeys)
{
sw_redis_command_key(INTERNAL_FUNCTION_PARAM_PASSTHRU, "HKEYS", 5);
}
static PHP_METHOD(swoole_redis_coro, hVals)
{
sw_redis_command_key(INTERNAL_FUNCTION_PARAM_PASSTHRU, "HVALS", 5);
}
static PHP_METHOD(swoole_redis_coro, hGetAll)
{
sw_redis_command_key(INTERNAL_FUNCTION_PARAM_PASSTHRU, "HGETALL", 7);
}
static PHP_METHOD(swoole_redis_coro, renameKey)
{
sw_redis_command_key_key(INTERNAL_FUNCTION_PARAM_PASSTHRU, "RENAME", 6);
}
static PHP_METHOD(swoole_redis_coro, renameNx)
{
sw_redis_command_key_key(INTERNAL_FUNCTION_PARAM_PASSTHRU, "RENAMENX", 8);
}
static PHP_METHOD(swoole_redis_coro, rpoplpush)
{
sw_redis_command_key_key(INTERNAL_FUNCTION_PARAM_PASSTHRU, "RPOPLPUSH", 9);
}
static PHP_METHOD(swoole_redis_coro, randomKey)
{
sw_redis_command_empty(INTERNAL_FUNCTION_PARAM_PASSTHRU, "RANDOMKEY", 9);
}
static PHP_METHOD(swoole_redis_coro, unwatch)
{
sw_redis_command_empty(INTERNAL_FUNCTION_PARAM_PASSTHRU, "UNWATCH", 7);
}
static PHP_METHOD(swoole_redis_coro, pfadd)
{
char *key;
size_t key_len, argc;
zval *z_arr;
if(zend_parse_parameters(ZEND_NUM_ARGS(), "sa", &key, &key_len,
&z_arr)==FAILURE)
{
return;
}
if((argc = zend_hash_num_elements(Z_ARRVAL_P(z_arr))) == 0) {
RETURN_FALSE;
}
SW_REDIS_COMMAND_CHECK
int i = 0;
argc = argc + 2;
zval *value;
SW_REDIS_COMMAND_ALLOC_ARGV
SW_REDIS_COMMAND_ARGV_FILL("PFADD", 5)
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
SW_HASHTABLE_FOREACH_START(Z_ARRVAL_P(z_arr), value) {
zend_string *convert_str = zval_get_string(value);
SW_REDIS_COMMAND_ARGV_FILL(ZSTR_VAL(convert_str), ZSTR_LEN(convert_str));
zend_string_release(convert_str);
} SW_HASHTABLE_FOREACH_END()
redis_request(redis, argc, argv, argvlen, return_value);
SW_REDIS_COMMAND_FREE_ARGV
}
static PHP_METHOD(swoole_redis_coro, pfcount)
{
int argc = ZEND_NUM_ARGS();
SW_REDIS_COMMAND_CHECK
SW_REDIS_COMMAND_ALLOC_ARGS_ARR
if(zend_get_parameters_array(ht, argc, z_args) == FAILURE || argc != 1)
{
efree(z_args);
RETURN_FALSE;
}
zend_bool single_array = 0;
if (SW_REDIS_COMMAND_ARGS_TYPE(z_args[0]) == IS_ARRAY)
{
argc = zend_hash_num_elements(SW_REDIS_COMMAND_ARGS_ARRVAL(z_args[0]));
single_array = 1;
}
argc += 1;
int i = 0;
SW_REDIS_COMMAND_ALLOC_ARGV
SW_REDIS_COMMAND_ARGV_FILL("PFCOUNT", 7)
if (single_array)
{
zval *value;
SW_HASHTABLE_FOREACH_START(SW_REDIS_COMMAND_ARGS_ARRVAL(z_args[0]), value)
zend_string *convert_str = zval_get_string(value);
SW_REDIS_COMMAND_ARGV_FILL(ZSTR_VAL(convert_str), ZSTR_LEN(convert_str))
zend_string_release(convert_str);
SW_HASHTABLE_FOREACH_END()
}
else
{
zend_string *convert_str = zval_get_string(&z_args[0]);
SW_REDIS_COMMAND_ARGV_FILL(ZSTR_VAL(convert_str), ZSTR_LEN(convert_str))
zend_string_release(convert_str);
}
efree(z_args);
redis_request(redis, argc, argv, argvlen, return_value);
SW_REDIS_COMMAND_FREE_ARGV
}
static PHP_METHOD(swoole_redis_coro, pfmerge)
{
char *key;
size_t key_len, argc;
zval *z_arr;
if(zend_parse_parameters(ZEND_NUM_ARGS(), "sa", &key, &key_len,
&z_arr)==FAILURE)
{
RETURN_FALSE;
}
if((argc = zend_hash_num_elements(Z_ARRVAL_P(z_arr))) == 0) {
RETURN_FALSE;
}
SW_REDIS_COMMAND_CHECK
int i = 0;
argc = argc + 2;
zval *value;
SW_REDIS_COMMAND_ALLOC_ARGV
SW_REDIS_COMMAND_ARGV_FILL("PFMERGE", 7)
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
SW_HASHTABLE_FOREACH_START(Z_ARRVAL_P(z_arr), value) {
zend_string *convert_str = zval_get_string(value);
SW_REDIS_COMMAND_ARGV_FILL(ZSTR_VAL(convert_str), ZSTR_LEN(convert_str));
zend_string_release(convert_str);
} SW_HASHTABLE_FOREACH_END()
redis_request(redis, argc, argv, argvlen, return_value);
SW_REDIS_COMMAND_FREE_ARGV
}
static PHP_METHOD(swoole_redis_coro, ping)
{
sw_redis_command_empty(INTERNAL_FUNCTION_PARAM_PASSTHRU, "PING", 4);
}
static PHP_METHOD(swoole_redis_coro, auth)
{
char *pw;
size_t pw_len;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &pw, &pw_len) == FAILURE)
{
RETURN_FALSE;
}
SW_REDIS_COMMAND_CHECK
zval *zsetting = sw_zend_read_property_array(swoole_redis_coro_ce, getThis(), ZEND_STRL("setting"), 1);
add_assoc_stringl(zsetting, "password", pw, pw_len);
RETURN_BOOL(redis_auth(redis, pw, pw_len));
}
static PHP_METHOD(swoole_redis_coro, save)
{
sw_redis_command_empty(INTERNAL_FUNCTION_PARAM_PASSTHRU, "SAVE", 4);
}
static PHP_METHOD(swoole_redis_coro, bgSave)
{
sw_redis_command_empty(INTERNAL_FUNCTION_PARAM_PASSTHRU, "BGSAVE", 6);
}
static PHP_METHOD(swoole_redis_coro, lastSave)
{
sw_redis_command_empty(INTERNAL_FUNCTION_PARAM_PASSTHRU, "LASTSAVE", 8);
}
static PHP_METHOD(swoole_redis_coro, flushDB)
{
sw_redis_command_empty(INTERNAL_FUNCTION_PARAM_PASSTHRU, "FLUSHDB", 7);
}
static PHP_METHOD(swoole_redis_coro, flushAll)
{
sw_redis_command_empty(INTERNAL_FUNCTION_PARAM_PASSTHRU, "FLUSHALL", 8);
}
static PHP_METHOD(swoole_redis_coro, dbSize)
{
sw_redis_command_empty(INTERNAL_FUNCTION_PARAM_PASSTHRU, "DBSIZE", 6);
}
static PHP_METHOD(swoole_redis_coro, bgrewriteaof)
{
sw_redis_command_empty(INTERNAL_FUNCTION_PARAM_PASSTHRU, "BGREWRITEAOF", 12);
}
static PHP_METHOD(swoole_redis_coro, time)
{
sw_redis_command_empty(INTERNAL_FUNCTION_PARAM_PASSTHRU, "TIME", 4);
}
static PHP_METHOD(swoole_redis_coro, role)
{
sw_redis_command_empty(INTERNAL_FUNCTION_PARAM_PASSTHRU, "ROLE", 4);
}
static PHP_METHOD(swoole_redis_coro, setRange)
{
sw_redis_command_key_long_str(INTERNAL_FUNCTION_PARAM_PASSTHRU, "SETRANGE", 8);
}
static PHP_METHOD(swoole_redis_coro, setNx)
{
sw_redis_command_key_val(INTERNAL_FUNCTION_PARAM_PASSTHRU, "SETNX", 5);
}
static PHP_METHOD(swoole_redis_coro, getSet)
{
sw_redis_command_key_val(INTERNAL_FUNCTION_PARAM_PASSTHRU, "GETSET", 6);
}
static PHP_METHOD(swoole_redis_coro, append)
{
sw_redis_command_key_val(INTERNAL_FUNCTION_PARAM_PASSTHRU, "APPEND", 6);
}
static PHP_METHOD(swoole_redis_coro, lPushx)
{
sw_redis_command_key_val(INTERNAL_FUNCTION_PARAM_PASSTHRU, "LPUSHX", 6);
}
static PHP_METHOD(swoole_redis_coro, lPush)
{
sw_redis_command_key_var_val(INTERNAL_FUNCTION_PARAM_PASSTHRU, "LPUSH", 5);
}
static PHP_METHOD(swoole_redis_coro, rPush)
{
sw_redis_command_key_var_val(INTERNAL_FUNCTION_PARAM_PASSTHRU, "RPUSH", 5);
}
static PHP_METHOD(swoole_redis_coro, rPushx)
{
sw_redis_command_key_val(INTERNAL_FUNCTION_PARAM_PASSTHRU, "RPUSHX", 6);
}
static PHP_METHOD(swoole_redis_coro, sContains)
{
sw_redis_command_key_val(INTERNAL_FUNCTION_PARAM_PASSTHRU, "SISMEMBER", 9);
}
static PHP_METHOD(swoole_redis_coro, zRange)
{
char *key;
size_t key_len;
zend_long start, end;
zend_bool ws = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sll|b", &key, &key_len, &start, &end, &ws) == FAILURE)
{
RETURN_FALSE;
}
SW_REDIS_COMMAND_CHECK
int i = 0, argc;
argc = ZEND_NUM_ARGS() + 1;
SW_REDIS_COMMAND_ALLOC_ARGV
SW_REDIS_COMMAND_ARGV_FILL("ZRANGE", 6)
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
char buf[32];
size_t buf_len;
buf_len = sw_snprintf(buf, sizeof(buf), "%ld", start);
SW_REDIS_COMMAND_ARGV_FILL((char* )buf, buf_len)
buf_len = sw_snprintf(buf, sizeof(buf), "%ld", end);
SW_REDIS_COMMAND_ARGV_FILL((char* )buf, buf_len)
if (ws)
{
SW_REDIS_COMMAND_ARGV_FILL("WITHSCORES", 10)
}
else
{
argc = 4;
}
redis_request(redis, argc, argv, argvlen, return_value);
SW_REDIS_COMMAND_FREE_ARGV
}
static PHP_METHOD(swoole_redis_coro, zRevRange)
{
char *key;
size_t key_len;
zend_long start, end;
zend_bool ws = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sll|b", &key, &key_len, &start, &end, &ws) == FAILURE)
{
RETURN_FALSE;
}
SW_REDIS_COMMAND_CHECK
int i = 0, argc;
argc = ZEND_NUM_ARGS() + 1;
SW_REDIS_COMMAND_ALLOC_ARGV
SW_REDIS_COMMAND_ARGV_FILL("ZREVRANGE", 9)
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
char buf[32];
size_t buf_len;
buf_len = sw_snprintf(buf, sizeof(buf), "%ld", start);
SW_REDIS_COMMAND_ARGV_FILL((char* )buf, buf_len)
buf_len = sw_snprintf(buf, sizeof(buf), "%ld", end);
SW_REDIS_COMMAND_ARGV_FILL((char* )buf, buf_len)
if (ws)
{
SW_REDIS_COMMAND_ARGV_FILL("WITHSCORES", 10)
}
else
{
argc = 4;
}
redis_request(redis, argc, argv, argvlen, return_value);
SW_REDIS_COMMAND_FREE_ARGV
}
static PHP_METHOD(swoole_redis_coro, zUnion)
{
char *key, *agg_op;
size_t key_len;
zval *z_keys, *z_weights=NULL;
HashTable *ht_keys, *ht_weights=NULL;
size_t argc = 2, agg_op_len=0, keys_count;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sa|a!s", &key, &key_len, &z_keys, &z_weights, &agg_op, &agg_op_len) == FAILURE)
{
RETURN_FALSE;
}
ht_keys = Z_ARRVAL_P(z_keys);
if ((keys_count = zend_hash_num_elements(ht_keys)) == 0)
{
RETURN_FALSE;
}
else
{
argc += keys_count + 1;
}
if (z_weights != NULL)
{
ht_weights = Z_ARRVAL_P(z_weights);
if (zend_hash_num_elements(ht_weights) != keys_count)
{
zend_update_property_long(swoole_redis_coro_ce, getThis(), ZEND_STRL("errType"), SW_REDIS_ERR_OTHER);
zend_update_property_long(swoole_redis_coro_ce, getThis(), ZEND_STRL("errCode"), sw_redis_convert_err(SW_REDIS_ERR_OTHER));
zend_update_property_string(swoole_redis_coro_ce, getThis(), ZEND_STRL("errMsg"), "WEIGHTS and keys array should be the same size!");
RETURN_FALSE
}
argc += keys_count + 1;
}
// AGGREGATE option
if (agg_op_len != 0)
{
if (strncasecmp(agg_op, "SUM", sizeof("SUM")) && strncasecmp(agg_op, "MIN", sizeof("MIN"))
&& strncasecmp(agg_op, "MAX", sizeof("MAX")))
{
zend_update_property_long(swoole_redis_coro_ce, getThis(), ZEND_STRL("errType"), SW_REDIS_ERR_OTHER);
zend_update_property_long(swoole_redis_coro_ce, getThis(), ZEND_STRL("errCode"), sw_redis_convert_err(SW_REDIS_ERR_OTHER));
zend_update_property_string(swoole_redis_coro_ce, getThis(), ZEND_STRL("errMsg"), "Invalid AGGREGATE option provided!");
RETURN_FALSE;
}
// "AGGREGATE" + type
argc += 2;
}
SW_REDIS_COMMAND_CHECK
int i = 0, j;
SW_REDIS_COMMAND_ALLOC_ARGV
SW_REDIS_COMMAND_ARGV_FILL("ZUNIONSTORE", 11)
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
char buf[32];
size_t buf_len;
buf_len = sprintf(buf, "%zu", keys_count);
SW_REDIS_COMMAND_ARGV_FILL(buf, buf_len)
// Process input keys
zval *value;
SW_HASHTABLE_FOREACH_START(ht_keys, value)
zend_string *convert_str = zval_get_string(value);
SW_REDIS_COMMAND_ARGV_FILL(ZSTR_VAL(convert_str), ZSTR_LEN(convert_str))
zend_string_release(convert_str);
SW_HASHTABLE_FOREACH_END();
// Weights
if(ht_weights != NULL) {
SW_REDIS_COMMAND_ARGV_FILL("WEIGHTS", 7)
SW_HASHTABLE_FOREACH_START(ht_weights, value)
if (Z_TYPE_P(value) != IS_LONG && Z_TYPE_P(value) != IS_DOUBLE
&& strncasecmp(Z_STRVAL_P(value), "inf", sizeof("inf")) != 0
&& strncasecmp(Z_STRVAL_P(value), "-inf", sizeof("-inf")) != 0
&& strncasecmp(Z_STRVAL_P(value), "+inf", sizeof("+inf")) != 0)
{
zend_update_property_long(swoole_redis_coro_ce, redis->zobject, ZEND_STRL("errType"), SW_REDIS_ERR_OTHER);
zend_update_property_long(swoole_redis_coro_ce, redis->zobject, ZEND_STRL("errCode"), sw_redis_convert_err(SW_REDIS_ERR_OTHER));
zend_update_property_string(swoole_redis_coro_ce, redis->zobject, ZEND_STRL("errMsg"), "Weights must be numeric or '-inf','inf','+inf'");
for (j = 0; j < i; j++)
{
efree((void* )argv[j]);
}
SW_REDIS_COMMAND_FREE_ARGV
RETURN_FALSE;
}
switch (Z_TYPE_P(value)) {
case IS_LONG:
buf_len = sprintf(buf, ZEND_LONG_FMT, Z_LVAL_P(value));
SW_REDIS_COMMAND_ARGV_FILL(buf, buf_len)
break;
case IS_DOUBLE:
buf_len = sprintf(buf, "%f", Z_DVAL_P(value));
SW_REDIS_COMMAND_ARGV_FILL(buf, buf_len)
break;
case IS_STRING:
SW_REDIS_COMMAND_ARGV_FILL(Z_STRVAL_P(value), Z_STRLEN_P(value))
break;
}
SW_HASHTABLE_FOREACH_END();
}
// AGGREGATE
if (agg_op_len != 0)
{
SW_REDIS_COMMAND_ARGV_FILL("AGGREGATE", 9)
SW_REDIS_COMMAND_ARGV_FILL(agg_op, agg_op_len)
}
redis_request(redis, argc, argv, argvlen, return_value);
SW_REDIS_COMMAND_FREE_ARGV
}
static PHP_METHOD(swoole_redis_coro, zInter)
{
char *key, *agg_op;
size_t key_len;
zval *z_keys, *z_weights=NULL;
HashTable *ht_keys, *ht_weights=NULL;
size_t argc = 2, agg_op_len=0, keys_count;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sa|a!s", &key, &key_len, &z_keys, &z_weights, &agg_op, &agg_op_len) == FAILURE)
{
RETURN_FALSE;
}
ht_keys = Z_ARRVAL_P(z_keys);
if ((keys_count = zend_hash_num_elements(ht_keys)) == 0)
{
RETURN_FALSE
}
else
{
argc += keys_count + 1;
}
if(z_weights != NULL) {
ht_weights = Z_ARRVAL_P(z_weights);
if(zend_hash_num_elements(ht_weights) != keys_count) {
zend_update_property_long(swoole_redis_coro_ce, getThis(), ZEND_STRL("errType"), SW_REDIS_ERR_OTHER);
zend_update_property_long(swoole_redis_coro_ce, getThis(), ZEND_STRL("errCode"), sw_redis_convert_err(SW_REDIS_ERR_OTHER));
zend_update_property_string(swoole_redis_coro_ce, getThis(), ZEND_STRL("errMsg"), "WEIGHTS and keys array should be the same size!");
RETURN_FALSE;
}
argc += keys_count + 1;
}
// AGGREGATE option
if(agg_op_len != 0) {
if(strncasecmp(agg_op, "SUM", sizeof("SUM")) &&
strncasecmp(agg_op, "MIN", sizeof("MIN")) &&
strncasecmp(agg_op, "MAX", sizeof("MAX")))
{
zend_update_property_long(swoole_redis_coro_ce, getThis(), ZEND_STRL("errType"), SW_REDIS_ERR_OTHER);
zend_update_property_long(swoole_redis_coro_ce, getThis(), ZEND_STRL("errCode"), sw_redis_convert_err(SW_REDIS_ERR_OTHER));
zend_update_property_string(swoole_redis_coro_ce, getThis(), ZEND_STRL("errMsg"), "Invalid AGGREGATE option provided!");
RETURN_FALSE;
}
// "AGGREGATE" + type
argc += 2;
}
SW_REDIS_COMMAND_CHECK
int i = 0, j;
SW_REDIS_COMMAND_ALLOC_ARGV
SW_REDIS_COMMAND_ARGV_FILL("ZINTERSTORE", 11)
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
char buf[32];
size_t buf_len;
buf_len = sprintf(buf, "%zu", keys_count);
SW_REDIS_COMMAND_ARGV_FILL(buf, buf_len)
// Process input keys
zval *value;
SW_HASHTABLE_FOREACH_START(ht_keys, value)
zend_string *convert_str = zval_get_string(value);
SW_REDIS_COMMAND_ARGV_FILL(ZSTR_VAL(convert_str), ZSTR_LEN(convert_str))
zend_string_release(convert_str);
SW_HASHTABLE_FOREACH_END();
// Weights
if(ht_weights != NULL) {
SW_REDIS_COMMAND_ARGV_FILL("WEIGHTS", 7)
SW_HASHTABLE_FOREACH_START(ht_weights, value)
if(Z_TYPE_P(value) != IS_LONG && Z_TYPE_P(value) != IS_DOUBLE &&
strncasecmp(Z_STRVAL_P(value),"inf",sizeof("inf")) != 0 &&
strncasecmp(Z_STRVAL_P(value),"-inf",sizeof("-inf")) != 0 &&
strncasecmp(Z_STRVAL_P(value),"+inf",sizeof("+inf")) != 0)
{
zend_update_property_long(swoole_redis_coro_ce, getThis(), ZEND_STRL("errType"), SW_REDIS_ERR_OTHER);
zend_update_property_long(swoole_redis_coro_ce, getThis(), ZEND_STRL("errCode"), sw_redis_convert_err(SW_REDIS_ERR_OTHER));
zend_update_property_string(swoole_redis_coro_ce, getThis(), ZEND_STRL("errMsg"), "Weights must be numeric or '-inf','inf','+inf'");
for (j = 0; j < i; j++)
{
efree((void* )argv[j]);
}
SW_REDIS_COMMAND_FREE_ARGV
RETURN_FALSE;
}
switch (Z_TYPE_P(value)) {
case IS_LONG:
buf_len = sprintf(buf, ZEND_LONG_FMT, Z_LVAL_P(value));
SW_REDIS_COMMAND_ARGV_FILL(buf, buf_len)
break;
case IS_DOUBLE:
buf_len = sprintf(buf, "%f", Z_DVAL_P(value));
SW_REDIS_COMMAND_ARGV_FILL(buf, buf_len)
break;
case IS_STRING:
SW_REDIS_COMMAND_ARGV_FILL(Z_STRVAL_P(value), Z_STRLEN_P(value))
break;
}
SW_HASHTABLE_FOREACH_END();
}
// AGGREGATE
if (agg_op_len != 0)
{
SW_REDIS_COMMAND_ARGV_FILL("AGGREGATE", 9)
SW_REDIS_COMMAND_ARGV_FILL(agg_op, agg_op_len)
}
redis_request(redis, argc, argv, argvlen, return_value);
SW_REDIS_COMMAND_FREE_ARGV
}
static PHP_METHOD(swoole_redis_coro, zRangeByLex)
{
char *key, *min, *max;
size_t key_len, min_len, max_len;
zend_long offset = 0, count = 0;
size_t argc = ZEND_NUM_ARGS();
/* We need either 3 or 5 arguments for this to be valid */
if(argc != 3 && argc != 5) {
zend_update_property_long(swoole_redis_coro_ce, getThis(), ZEND_STRL("errType"), SW_REDIS_ERR_OTHER);
zend_update_property_long(swoole_redis_coro_ce, getThis(), ZEND_STRL("errCode"), sw_redis_convert_err(SW_REDIS_ERR_OTHER));
zend_update_property_string(swoole_redis_coro_ce, getThis(), ZEND_STRL("errMsg"), "Must pass either 3 or 5 arguments");
RETURN_FALSE;
}
if (zend_parse_parameters(argc, "sss|ll", &key, &key_len, &min, &min_len, &max, &max_len, &offset, &count) == FAILURE)
{
RETURN_FALSE;
}
/* min and max must start with '(' or '[', or be either '-' or '+' */
if (min_len < 1 || max_len < 1
|| (min[0] != '(' && min[0] != '[' && (min[0] != '-' || min_len > 1) && (min[0] != '+' || min_len > 1))
|| (max[0] != '(' && max[0] != '[' && (max[0] != '-' || max_len > 1) && (max[0] != '+' || max_len > 1)))
{
zend_update_property_long(swoole_redis_coro_ce, getThis(), ZEND_STRL("errType"), SW_REDIS_ERR_OTHER);
zend_update_property_long(swoole_redis_coro_ce, getThis(), ZEND_STRL("errCode"), sw_redis_convert_err(SW_REDIS_ERR_OTHER));
zend_update_property_string(swoole_redis_coro_ce, getThis(), ZEND_STRL("errMsg"), "min and max arguments must start with '[' or '('");
RETURN_FALSE;
}
SW_REDIS_COMMAND_CHECK
argc = argc == 3 ? 4 : 7;
int i = 0;
SW_REDIS_COMMAND_ALLOC_ARGV
SW_REDIS_COMMAND_ARGV_FILL("ZRANGEBYLEX", 11)
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
SW_REDIS_COMMAND_ARGV_FILL(min, min_len)
SW_REDIS_COMMAND_ARGV_FILL(max, max_len)
if (argc == 7)
{
SW_REDIS_COMMAND_ARGV_FILL("LIMIT", 5)
char buf[32];
size_t buf_len;
buf_len = sprintf(buf, ZEND_LONG_FMT, offset);
SW_REDIS_COMMAND_ARGV_FILL(buf, buf_len)
buf_len = sprintf(buf, ZEND_LONG_FMT, count);
SW_REDIS_COMMAND_ARGV_FILL(buf, buf_len)
}
redis_request(redis, argc, argv, argvlen, return_value);
SW_REDIS_COMMAND_FREE_ARGV
}
static PHP_METHOD(swoole_redis_coro, zRevRangeByLex)
{
char *key, *min, *max;
size_t key_len, min_len, max_len;
zend_long offset = 0, count = 0;
int argc = ZEND_NUM_ARGS();
/* We need either 3 or 5 arguments for this to be valid */
if(argc != 3 && argc != 5) {
zend_update_property_long(swoole_redis_coro_ce, getThis(), ZEND_STRL("errType"), SW_REDIS_ERR_OTHER);
zend_update_property_long(swoole_redis_coro_ce, getThis(), ZEND_STRL("errCode"), sw_redis_convert_err(SW_REDIS_ERR_OTHER));
zend_update_property_string(swoole_redis_coro_ce, getThis(), ZEND_STRL("errMsg"), "Must pass either 3 or 5 arguments");
RETURN_FALSE;
}
if (zend_parse_parameters(argc, "sss|ll", &key, &key_len, &min, &min_len, &max, &max_len, &offset, &count) == FAILURE)
{
RETURN_FALSE;
}
/* min and max must start with '(' or '[', or be either '-' or '+' */
if (min_len < 1 || max_len < 1
|| (min[0] != '(' && min[0] != '[' && (min[0] != '-' || min_len > 1) && (min[0] != '+' || min_len > 1))
|| (max[0] != '(' && max[0] != '[' && (max[0] != '-' || max_len > 1) && (max[0] != '+' || max_len > 1)))
{
zend_update_property_long(swoole_redis_coro_ce, getThis(), ZEND_STRL("errType"), SW_REDIS_ERR_OTHER);
zend_update_property_long(swoole_redis_coro_ce, getThis(), ZEND_STRL("errCode"), sw_redis_convert_err(SW_REDIS_ERR_OTHER));
zend_update_property_string(swoole_redis_coro_ce, getThis(), ZEND_STRL("errMsg"), "min and max arguments must start with '[' or '('");
RETURN_FALSE;
}
SW_REDIS_COMMAND_CHECK
argc = argc == 3 ? 4 : 7;
int i = 0;
SW_REDIS_COMMAND_ALLOC_ARGV
SW_REDIS_COMMAND_ARGV_FILL("ZREVRANGEBYLEX", 14)
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
SW_REDIS_COMMAND_ARGV_FILL(min, min_len)
SW_REDIS_COMMAND_ARGV_FILL(max, max_len)
if (argc == 7)
{
SW_REDIS_COMMAND_ARGV_FILL("LIMIT", 5)
char buf[32];
size_t buf_len;
buf_len = sprintf(buf, ZEND_LONG_FMT, offset);
SW_REDIS_COMMAND_ARGV_FILL(buf, buf_len)
buf_len = sprintf(buf, ZEND_LONG_FMT, count);
SW_REDIS_COMMAND_ARGV_FILL(buf, buf_len)
}
redis_request(redis, argc, argv, argvlen, return_value);
SW_REDIS_COMMAND_FREE_ARGV
}
static PHP_METHOD(swoole_redis_coro, zRangeByScore)
{
char *key;
size_t key_len;
char *start, *end;
size_t start_len, end_len;
long limit_low, limit_high;
zval *z_opt=NULL, *z_ele;
zend_bool withscores = 0, has_limit = 0;
HashTable *ht_opt;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sss|a", &key, &key_len, &start, &start_len, &end, &end_len, &z_opt) == FAILURE)
{
RETURN_FALSE;
}
SW_REDIS_COMMAND_CHECK
int argc = 4, i = 0;
// Check for an options array
if (z_opt && Z_TYPE_P(z_opt) == IS_ARRAY)
{
ht_opt = Z_ARRVAL_P(z_opt);
// Check for WITHSCORES
if ((z_ele = zend_hash_str_find(ht_opt, ZEND_STRL("withscores")))
&& Z_TYPE_P(z_ele) == IS_TRUE
)
{
withscores = 1;
argc++;
}
// LIMIT
if ((z_ele = zend_hash_str_find(ht_opt, ZEND_STRL("limit"))))
{
HashTable *ht_limit = Z_ARRVAL_P(z_ele);
zval *z_off, *z_cnt;
z_off = zend_hash_index_find(ht_limit, 0);
z_cnt = zend_hash_index_find(ht_limit, 1);
if (z_off && z_cnt && Z_TYPE_P(z_off) == IS_LONG && Z_TYPE_P(z_cnt) == IS_LONG)
{
has_limit = 1;
limit_low = Z_LVAL_P(z_off);
limit_high = Z_LVAL_P(z_cnt);
argc += 3;
}
}
}
SW_REDIS_COMMAND_ALLOC_ARGV
SW_REDIS_COMMAND_ARGV_FILL("ZRANGEBYSCORE", 13)
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
SW_REDIS_COMMAND_ARGV_FILL(start, start_len)
SW_REDIS_COMMAND_ARGV_FILL(end, end_len)
if (withscores)
{
SW_REDIS_COMMAND_ARGV_FILL("WITHSCORES", 10)
}
if (has_limit)
{
SW_REDIS_COMMAND_ARGV_FILL("LIMIT", 5)
char buf[32];
size_t buf_len;
buf_len = sprintf(buf, "%ld", limit_low);
SW_REDIS_COMMAND_ARGV_FILL(buf, buf_len)
buf_len = sprintf(buf, "%ld", limit_high);
SW_REDIS_COMMAND_ARGV_FILL(buf, buf_len)
}
redis_request(redis, argc, argv, argvlen, return_value);
SW_REDIS_COMMAND_FREE_ARGV
}
static PHP_METHOD(swoole_redis_coro, zRevRangeByScore)
{
char *key;
size_t key_len;
char *start, *end;
size_t start_len, end_len;
long limit_low, limit_high;
zval *z_opt=NULL, *z_ele;
zend_bool withscores = 0, has_limit = 0;
HashTable *ht_opt;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sss|a", &key, &key_len, &start, &start_len, &end, &end_len, &z_opt) == FAILURE)
{
RETURN_FALSE;
}
SW_REDIS_COMMAND_CHECK
int argc = 4, i = 0;
// Check for an options array
if (z_opt && Z_TYPE_P(z_opt) == IS_ARRAY)
{
ht_opt = Z_ARRVAL_P(z_opt);
// Check for WITHSCORES
if ((z_ele = zend_hash_str_find(ht_opt, ZEND_STRL("withscores")))
&& Z_TYPE_P(z_ele) == IS_TRUE
)
{
withscores = 1;
argc++;
}
// LIMIT
if ((z_ele = zend_hash_str_find(ht_opt, ZEND_STRL("limit"))))
{
HashTable *ht_limit = Z_ARRVAL_P(z_ele);
zval *z_off, *z_cnt;
z_off = zend_hash_index_find(ht_limit,0);
z_cnt = zend_hash_index_find(ht_limit, 1);
if (z_off && z_cnt && Z_TYPE_P(z_off) == IS_LONG && Z_TYPE_P(z_cnt) == IS_LONG)
{
has_limit = 1;
limit_low = Z_LVAL_P(z_off);
limit_high = Z_LVAL_P(z_cnt);
argc += 3;
}
}
}
SW_REDIS_COMMAND_ALLOC_ARGV
SW_REDIS_COMMAND_ARGV_FILL("ZREVRANGEBYSCORE", 16)
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
SW_REDIS_COMMAND_ARGV_FILL(start, start_len)
SW_REDIS_COMMAND_ARGV_FILL(end, end_len)
if (withscores)
{
SW_REDIS_COMMAND_ARGV_FILL("WITHSCORES", 10)
}
if (has_limit)
{
SW_REDIS_COMMAND_ARGV_FILL("LIMIT", 5)
char buf[32];
size_t buf_len;
buf_len = sprintf(buf, "%ld", limit_low);
SW_REDIS_COMMAND_ARGV_FILL(buf, buf_len)
buf_len = sprintf(buf, "%ld", limit_high);
SW_REDIS_COMMAND_ARGV_FILL(buf, buf_len)
}
redis_request(redis, argc, argv, argvlen, return_value);
SW_REDIS_COMMAND_FREE_ARGV
}
static PHP_METHOD(swoole_redis_coro, zIncrBy)
{
char *key;
size_t key_len;
double incrby;
zval *z_val;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sdz", &key, &key_len, &incrby, &z_val) == FAILURE)
{
RETURN_FALSE;
}
SW_REDIS_COMMAND_CHECK;
int i = 0;
size_t argvlen[4];
char *argv[4];
SW_REDIS_COMMAND_ARGV_FILL("ZINCRBY", 7)
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
char buf[32];
size_t buf_len;
buf_len = sprintf(buf, "%f", incrby);
SW_REDIS_COMMAND_ARGV_FILL(buf, buf_len)
SW_REDIS_COMMAND_ARGV_FILL_WITH_SERIALIZE(z_val)
redis_request(redis, 4, argv, argvlen, return_value);
}
static PHP_METHOD(swoole_redis_coro, zAdd)
{
int argc = ZEND_NUM_ARGS();
SW_REDIS_COMMAND_CHECK
SW_REDIS_COMMAND_ALLOC_ARGS_ARR
if (zend_get_parameters_array(ht, argc, z_args) == FAILURE)
{
efree(z_args);
RETURN_FALSE;
}
if (argc > 0)
{
convert_to_string(&z_args[0]);
}
if (argc < 3 || SW_REDIS_COMMAND_ARGS_TYPE(z_args[0]) != IS_STRING)
{
efree(z_args);
RETURN_FALSE;
}
int i = 0, j, k, valid_params;
valid_params = argc - 1;
argc++;
SW_REDIS_COMMAND_ALLOC_ARGV
SW_REDIS_COMMAND_ARGV_FILL("ZADD", 4)
SW_REDIS_COMMAND_ARGV_FILL(SW_REDIS_COMMAND_ARGS_STRVAL(z_args[0]), (size_t)SW_REDIS_COMMAND_ARGS_STRLEN(z_args[0]))
k = 1;
if (SW_REDIS_COMMAND_ARGS_TYPE(z_args[k]) == IS_STRING && IS_NX_XX_ARG(SW_REDIS_COMMAND_ARGS_STRVAL(z_args[k])))
{
SW_REDIS_COMMAND_ARGV_FILL(SW_REDIS_COMMAND_ARGS_STRVAL(z_args[k]), (size_t)SW_REDIS_COMMAND_ARGS_STRLEN(z_args[k]))
k++;
valid_params--;
}
if (SW_REDIS_COMMAND_ARGS_TYPE(z_args[k]) == IS_STRING && strncasecmp(SW_REDIS_COMMAND_ARGS_STRVAL(z_args[k]), "CH", 2) == 0)
{
SW_REDIS_COMMAND_ARGV_FILL("CH", 2)
k++;
valid_params--;
}
if (SW_REDIS_COMMAND_ARGS_TYPE(z_args[k]) == IS_STRING && strncasecmp(SW_REDIS_COMMAND_ARGS_STRVAL(z_args[k]), "INCR", 4) == 0)
{
SW_REDIS_COMMAND_ARGV_FILL("INCR", 4)
k++;
valid_params--;
}
if (valid_params % 2 != 0)
{
for (i = 0; i < 1 + k; i++)
{
efree((void* )argv[i]);
}
SW_REDIS_COMMAND_FREE_ARGV
efree(z_args);
RETURN_FALSE;
}
char buf[32];
size_t buf_len;
for (j = k; j < argc - 1; j += 2)
{
buf_len = sw_snprintf(buf, sizeof(buf), "%f", zval_get_double(&z_args[j]));
SW_REDIS_COMMAND_ARGV_FILL((char* )buf, buf_len)
SW_REDIS_COMMAND_ARGV_FILL_WITH_SERIALIZE(SW_REDIS_COMMAND_ARGS_REF(z_args[j+1]))
}
efree(z_args);
redis_request(redis, argc, argv, argvlen, return_value);;
SW_REDIS_COMMAND_FREE_ARGV
}
static PHP_METHOD(swoole_redis_coro, zScore)
{
sw_redis_command_key_val(INTERNAL_FUNCTION_PARAM_PASSTHRU, "ZSCORE", 6);
}
static PHP_METHOD(swoole_redis_coro, zRank)
{
sw_redis_command_key_val(INTERNAL_FUNCTION_PARAM_PASSTHRU, "ZRANK", 5);
}
static PHP_METHOD(swoole_redis_coro, zRevRank)
{
sw_redis_command_key_val(INTERNAL_FUNCTION_PARAM_PASSTHRU, "ZREVRANK", 8);
}
static PHP_METHOD(swoole_redis_coro, hGet)
{
sw_redis_command_key_str(INTERNAL_FUNCTION_PARAM_PASSTHRU, "HGET", 4);
}
static PHP_METHOD(swoole_redis_coro, hMGet)
{
char *key;
zval *z_arr;
size_t argc, key_len;
HashTable *ht_chan;
if(zend_parse_parameters(ZEND_NUM_ARGS(), "sa", &key, &key_len,
&z_arr)==FAILURE)
{
return;
}
ht_chan = Z_ARRVAL_P(z_arr);
if((argc = zend_hash_num_elements(ht_chan)) == 0) {
RETURN_FALSE;
}
SW_REDIS_COMMAND_CHECK
zval *value;
int i = 0;
argc = argc + 2;
SW_REDIS_COMMAND_ALLOC_ARGV
SW_REDIS_COMMAND_ARGV_FILL("HMGET", 5)
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
SW_HASHTABLE_FOREACH_START(ht_chan, value)
zend_string *convert_str = zval_get_string(value);
SW_REDIS_COMMAND_ARGV_FILL(ZSTR_VAL(convert_str), ZSTR_LEN(convert_str))
zend_string_release(convert_str);
SW_HASHTABLE_FOREACH_END();
redis_request(redis, argc, argv, argvlen, return_value);
SW_REDIS_COMMAND_FREE_ARGV
}
static PHP_METHOD(swoole_redis_coro, hExists)
{
sw_redis_command_key_str(INTERNAL_FUNCTION_PARAM_PASSTHRU, "HEXISTS", 7);
}
static PHP_METHOD(swoole_redis_coro, publish)
{
sw_redis_command_key_str(INTERNAL_FUNCTION_PARAM_PASSTHRU, "PUBLISH", 7);
}
static PHP_METHOD(swoole_redis_coro, zDeleteRangeByScore)
{
sw_redis_command_key_str_str(INTERNAL_FUNCTION_PARAM_PASSTHRU, "ZREMRANGEBYSCORE", 16);
}
static PHP_METHOD(swoole_redis_coro, zCount)
{
sw_redis_command_key_str_str(INTERNAL_FUNCTION_PARAM_PASSTHRU, "ZCOUNT", 6);
}
static PHP_METHOD(swoole_redis_coro, incrBy)
{
sw_redis_command_key_long(INTERNAL_FUNCTION_PARAM_PASSTHRU, "INCRBY", 6);
}
static PHP_METHOD(swoole_redis_coro, hIncrBy)
{
char *key, *mem;
size_t key_len, mem_len;
long byval;
if(zend_parse_parameters(ZEND_NUM_ARGS(), "ssl", &key, &key_len,
&mem, &mem_len, &byval)==FAILURE)
{
return;
}
SW_REDIS_COMMAND_CHECK
int i = 0;
size_t argvlen[4];
char *argv[4];
SW_REDIS_COMMAND_ARGV_FILL("HINCRBY", 7)
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
SW_REDIS_COMMAND_ARGV_FILL(mem, mem_len)
char str[32];
sprintf(str, "%ld", byval);
SW_REDIS_COMMAND_ARGV_FILL(str, strlen(str))
redis_request(redis, 4, argv, argvlen, return_value);
}
static PHP_METHOD(swoole_redis_coro, hIncrByFloat)
{
char *key, *mem;
size_t key_len, mem_len;
double byval;
if(zend_parse_parameters(ZEND_NUM_ARGS(), "ssd", &key, &key_len,
&mem, &mem_len, &byval)==FAILURE)
{
return;
}
SW_REDIS_COMMAND_CHECK
int i = 0;
size_t argvlen[4];
char *argv[4];
SW_REDIS_COMMAND_ARGV_FILL("HINCRBYFLOAT", 12)
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
SW_REDIS_COMMAND_ARGV_FILL(mem, mem_len)
char str[32];
sprintf(str, "%f", byval);
SW_REDIS_COMMAND_ARGV_FILL(str, strlen(str))
redis_request(redis, 4, argv, argvlen, return_value);
}
static PHP_METHOD(swoole_redis_coro, incr)
{
sw_redis_command_key(INTERNAL_FUNCTION_PARAM_PASSTHRU, "INCR", 4);
}
static PHP_METHOD(swoole_redis_coro, decrBy)
{
sw_redis_command_key_long(INTERNAL_FUNCTION_PARAM_PASSTHRU, "DECRBY", 6);
}
static PHP_METHOD(swoole_redis_coro, decr)
{
sw_redis_command_key(INTERNAL_FUNCTION_PARAM_PASSTHRU, "DECR", 4);
}
static PHP_METHOD(swoole_redis_coro, getBit)
{
sw_redis_command_key_long(INTERNAL_FUNCTION_PARAM_PASSTHRU, "GETBIT", 6);
}
static PHP_METHOD(swoole_redis_coro, lInsert)
{
char *key, *pos;
size_t key_len, pos_len;
zval *z_val, *z_pivot;
if(zend_parse_parameters(ZEND_NUM_ARGS(), "sszz", &key, &key_len,
&pos, &pos_len, &z_pivot, &z_val) == FAILURE)
{
return;
}
if (strncasecmp(pos, "after", 5) && strncasecmp(pos, "before", 6)) {
swoole_php_error(E_WARNING, "Position must be either 'BEFORE' or 'AFTER'");
RETURN_FALSE;
}
SW_REDIS_COMMAND_CHECK
int i = 0;
size_t argvlen[5];
char *argv[5];
SW_REDIS_COMMAND_ARGV_FILL("LINSERT", 7)
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
SW_REDIS_COMMAND_ARGV_FILL(pos, pos_len)
SW_REDIS_COMMAND_ARGV_FILL_WITH_SERIALIZE(z_pivot)
SW_REDIS_COMMAND_ARGV_FILL_WITH_SERIALIZE(z_val)
redis_request(redis, 5, argv, argvlen, return_value);
}
static PHP_METHOD(swoole_redis_coro, lGet)
{
sw_redis_command_key_long(INTERNAL_FUNCTION_PARAM_PASSTHRU, "LINDEX", 6);
}
static PHP_METHOD(swoole_redis_coro, setTimeout)
{
sw_redis_command_key_long(INTERNAL_FUNCTION_PARAM_PASSTHRU, "EXPIRE", 6);
}
static PHP_METHOD(swoole_redis_coro, pexpire)
{
sw_redis_command_key_long(INTERNAL_FUNCTION_PARAM_PASSTHRU, "PEXPIRE", 7);
}
static PHP_METHOD(swoole_redis_coro, expireAt)
{
sw_redis_command_key_long(INTERNAL_FUNCTION_PARAM_PASSTHRU, "EXPIREAT", 8);
}
static PHP_METHOD(swoole_redis_coro, pexpireAt)
{
sw_redis_command_key_long(INTERNAL_FUNCTION_PARAM_PASSTHRU, "PEXPIREAT", 9);
}
static PHP_METHOD(swoole_redis_coro, move)
{
sw_redis_command_key_long(INTERNAL_FUNCTION_PARAM_PASSTHRU, "MOVE", 4);
}
static PHP_METHOD(swoole_redis_coro, select)
{
zend_long db_number;
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_LONG(db_number)
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
SW_REDIS_COMMAND_CHECK
zval *zsetting = sw_zend_read_property_array(swoole_redis_coro_ce, getThis(), ZEND_STRL("setting"), 1);
add_assoc_long(zsetting, "database", db_number);
RETURN_BOOL(redis_select_db(redis, db_number));
}
static PHP_METHOD(swoole_redis_coro, getRange)
{
sw_redis_command_key_long_long(INTERNAL_FUNCTION_PARAM_PASSTHRU, "GETRANGE", 8);
}
static PHP_METHOD(swoole_redis_coro, listTrim)
{
sw_redis_command_key_long_long(INTERNAL_FUNCTION_PARAM_PASSTHRU, "LTRIM", 5);
}
static PHP_METHOD(swoole_redis_coro, lGetRange)
{
sw_redis_command_key_long_long(INTERNAL_FUNCTION_PARAM_PASSTHRU, "LRANGE", 6);
}
static PHP_METHOD(swoole_redis_coro, lRem)
{
char *key;
size_t key_len;
zend_long count = 0;
zval *z_val;
if(zend_parse_parameters(ZEND_NUM_ARGS(), "sz|l", &key, &key_len, &z_val, &count) == FAILURE)
{
RETURN_FALSE;
}
SW_REDIS_COMMAND_CHECK
int i = 0;
size_t argvlen[4];
char *argv[4];
SW_REDIS_COMMAND_ARGV_FILL("LREM", 4)
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
char str[32];
sprintf(str, "%d", (int)count);
SW_REDIS_COMMAND_ARGV_FILL(str, strlen(str))
SW_REDIS_COMMAND_ARGV_FILL_WITH_SERIALIZE(z_val)
redis_request(redis, 4, argv, argvlen, return_value);
}
static PHP_METHOD(swoole_redis_coro, zDeleteRangeByRank)
{
sw_redis_command_key_long_long(INTERNAL_FUNCTION_PARAM_PASSTHRU, "ZREMRANGEBYRANK", 15);
}
static PHP_METHOD(swoole_redis_coro, incrByFloat)
{
sw_redis_command_key_dbl(INTERNAL_FUNCTION_PARAM_PASSTHRU, "INCRBYFLOAT", 11);
}
static PHP_METHOD(swoole_redis_coro, bitCount)
{
char *key;
size_t key_len;
zend_long start = 0, end = -1;
if(zend_parse_parameters(ZEND_NUM_ARGS(), "s|ll", &key, &key_len, &start, &end) == FAILURE)
{
return;
}
SW_REDIS_COMMAND_CHECK
int i = 0;
size_t argvlen[4];
char *argv[4];
SW_REDIS_COMMAND_ARGV_FILL("BITCOUNT", 8)
SW_REDIS_COMMAND_ARGV_FILL(key, key_len)
char str[32];
sprintf(str, "%d", (int)start);
SW_REDIS_COMMAND_ARGV_FILL(str, strlen(str))
sprintf(str, "%d", (int)end);
SW_REDIS_COMMAND_ARGV_FILL(str, strlen(str))
redis_request(redis, 4, argv, argvlen, return_value);
}
static PHP_METHOD(swoole_redis_coro, bitOp)
{
int argc = ZEND_NUM_ARGS();
SW_REDIS_COMMAND_CHECK
SW_REDIS_COMMAND_ALLOC_ARGS_ARR
if(zend_get_parameters_array(ht, argc, z_args) == FAILURE ||
argc < 3 || SW_REDIS_COMMAND_ARGS_TYPE(z_args[0]) != IS_STRING)
{
efree(z_args);
return;
}
int j, i = 0;
argc++;
SW_REDIS_COMMAND_ALLOC_ARGV
SW_REDIS_COMMAND_ARGV_FILL("BITOP", 5)
SW_REDIS_COMMAND_ARGV_FILL(SW_REDIS_COMMAND_ARGS_STRVAL(z_args[0]), SW_REDIS_COMMAND_ARGS_STRLEN(z_args[0]))
for(j = 1; j < argc - 1; j++) {
zend_string *convert_str = zval_get_string(&z_args[j]);
SW_REDIS_COMMAND_ARGV_FILL(ZSTR_VAL(convert_str), ZSTR_LEN(convert_str))
zend_string_release(convert_str);
}
redis_request(redis, argc, argv, argvlen, return_value);
SW_REDIS_COMMAND_FREE_ARGV
efree(z_args);
}
static PHP_METHOD(swoole_redis_coro, sMove)
{
char *src, *dst;
size_t src_len, dst_len;
zval *z_val;
if(zend_parse_parameters(ZEND_NUM_ARGS(), "ssz", &src, &src_len,
&dst, &dst_len, &z_val) == FAILURE)
{
return;
}
SW_REDIS_COMMAND_CHECK
int i = 0;
size_t argvlen[4];
char *argv[4];
SW_REDIS_COMMAND_ARGV_FILL("SMOVE", 5)
SW_REDIS_COMMAND_ARGV_FILL(src, src_len)
SW_REDIS_COMMAND_ARGV_FILL(dst, dst_len)
SW_REDIS_COMMAND_ARGV_FILL_WITH_SERIALIZE(z_val)
redis_request(redis, 4, argv, argvlen, return_value);
}
static PHP_METHOD(swoole_redis_coro, sAdd)
{
sw_redis_command_key_var_val(INTERNAL_FUNCTION_PARAM_PASSTHRU, "SADD", 4);
}
static PHP_METHOD(swoole_redis_coro, sRemove)
{
sw_redis_command_key_var_val(INTERNAL_FUNCTION_PARAM_PASSTHRU, "SREM", 4);
}
static PHP_METHOD(swoole_redis_coro, zDelete)
{
sw_redis_command_key_var_val(INTERNAL_FUNCTION_PARAM_PASSTHRU, "ZREM", 4);
}
static sw_inline void redis_subscribe(INTERNAL_FUNCTION_PARAMETERS, const char *cmd)
{
zval *z_arr;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &z_arr) == FAILURE)
{
RETURN_FALSE;
}
SW_REDIS_COMMAND_CHECK
if (redis->defer)
{
zend_update_property_long(swoole_redis_coro_ce, getThis(), ZEND_STRL("errType"), SW_REDIS_ERR_OTHER);
zend_update_property_long(swoole_redis_coro_ce, getThis(), ZEND_STRL("errCode"), sw_redis_convert_err(SW_REDIS_ERR_OTHER));
zend_update_property_string(swoole_redis_coro_ce, getThis(), ZEND_STRL("errMsg"), "subscribe cannot be used with defer enabled");
RETURN_FALSE;
}
HashTable *ht_chan = Z_ARRVAL_P(z_arr);
size_t chan_num = zend_hash_num_elements(ht_chan);
int argc = 1 + chan_num, i = 0;
SW_REDIS_COMMAND_ALLOC_ARGV
SW_REDIS_COMMAND_ARGV_FILL(cmd, strlen(cmd));
zval *value;
SW_HASHTABLE_FOREACH_START(ht_chan, value)
zend_string *convert_str = zval_get_string(value);
SW_REDIS_COMMAND_ARGV_FILL(ZSTR_VAL(convert_str), ZSTR_LEN(convert_str))
zend_string_release(convert_str);
SW_HASHTABLE_FOREACH_END();
redis->defer = true;
redis_request(redis, argc, argv, argvlen, return_value);
redis->defer = false;
SW_REDIS_COMMAND_FREE_ARGV
if (Z_TYPE_P(return_value) == IS_TRUE)
{
redis->session.subscribe = true;
}
}
static PHP_METHOD(swoole_redis_coro, subscribe)
{
redis_subscribe(INTERNAL_FUNCTION_PARAM_PASSTHRU, "SUBSCRIBE");
}
static PHP_METHOD(swoole_redis_coro, pSubscribe)
{
redis_subscribe(INTERNAL_FUNCTION_PARAM_PASSTHRU, "PSUBSCRIBE");
}
static PHP_METHOD(swoole_redis_coro, unsubscribe)
{
redis_subscribe(INTERNAL_FUNCTION_PARAM_PASSTHRU, "UNSUBSCRIBE");
}
static PHP_METHOD(swoole_redis_coro, pUnSubscribe)
{
redis_subscribe(INTERNAL_FUNCTION_PARAM_PASSTHRU, "PUNSUBSCRIBE");
}
static PHP_METHOD(swoole_redis_coro, multi)
{
sw_redis_command_empty(INTERNAL_FUNCTION_PARAM_PASSTHRU, "MULTI", 5);
}
static PHP_METHOD(swoole_redis_coro, exec)
{
sw_redis_command_empty(INTERNAL_FUNCTION_PARAM_PASSTHRU, "EXEC", 4);
}
static PHP_METHOD(swoole_redis_coro, request)
{
SW_REDIS_COMMAND_CHECK
zval *params = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &params) == FAILURE)
{
RETURN_FALSE;
}
int argc = zend_hash_num_elements(Z_ARRVAL_P(params));
int i = 0;
zval *value;
SW_REDIS_COMMAND_ALLOC_ARGV
SW_HASHTABLE_FOREACH_START(Z_ARRVAL_P(params), value)
if (i == argc)
{
break;
}
zend_string *convert_str = zval_get_string(value);
argvlen[i] = ZSTR_LEN(convert_str);
argv[i] = estrndup(ZSTR_VAL(convert_str), ZSTR_LEN(convert_str));
zend_string_release(convert_str);
i++;
SW_HASHTABLE_FOREACH_END();
redis_request(redis, argc, argv, argvlen, return_value);
SW_REDIS_COMMAND_FREE_ARGV
}
static PHP_METHOD(swoole_redis_coro, eval)
{
char *script;
size_t script_len;
zval *params = NULL;
zend_long keys_num = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|al", &script, &script_len, &params, &keys_num) == FAILURE)
{
RETURN_FALSE;
}
HashTable *params_ht = NULL;
uint32_t params_num = 0;
if (params)
{
params_ht = Z_ARRVAL_P(params);
params_num = zend_hash_num_elements(params_ht);
}
SW_REDIS_COMMAND_CHECK
int i = 0;
size_t *argvlen = (size_t *) emalloc(sizeof(size_t) * (params_num + 3));
char **argv = (char **) emalloc(sizeof(char *) * (params_num + 3));
SW_REDIS_COMMAND_ARGV_FILL("EVAL", 4)
SW_REDIS_COMMAND_ARGV_FILL(script, script_len)
char keys_num_str[32] = {0};
sprintf(keys_num_str, ZEND_LONG_FMT, keys_num);
SW_REDIS_COMMAND_ARGV_FILL(keys_num_str, strlen(keys_num_str));
if (params_ht)
{
zval *param;
SW_HASHTABLE_FOREACH_START(params_ht, param)
zend_string *param_str = zval_get_string(param);
SW_REDIS_COMMAND_ARGV_FILL(ZSTR_VAL(param_str), ZSTR_LEN(param_str))
zend_string_release(param_str);
SW_HASHTABLE_FOREACH_END();
}
redis_request(redis, params_num + 3, argv, argvlen, return_value);
efree(argvlen);
efree(argv);
}
static PHP_METHOD(swoole_redis_coro, evalSha)
{
char *sha;
size_t sha_len;
zval *params = NULL;
long keys_num = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|al", &sha, &sha_len, &params, &keys_num) == FAILURE)
{
RETURN_FALSE;
}
HashTable *params_ht = NULL;
uint32_t params_num = 0;
if (params)
{
params_ht = Z_ARRVAL_P(params);
params_num = zend_hash_num_elements(params_ht);
}
SW_REDIS_COMMAND_CHECK
int i = 0;
size_t *argvlen = (size_t *) emalloc(sizeof(size_t) * (params_num + 3));
char **argv = (char **) emalloc(sizeof(char *) * (params_num + 3));
SW_REDIS_COMMAND_ARGV_FILL("EVALSHA", 7)
SW_REDIS_COMMAND_ARGV_FILL(sha, sha_len)
char keys_num_str[32] = {0};
sprintf(keys_num_str, "%ld", keys_num);
SW_REDIS_COMMAND_ARGV_FILL(keys_num_str, strlen(keys_num_str));
if (params)
{
zval *param;
SW_HASHTABLE_FOREACH_START(params_ht, param)
zend_string *param_str = zval_get_string(param);
SW_REDIS_COMMAND_ARGV_FILL(ZSTR_VAL(param_str), ZSTR_LEN(param_str))
zend_string_release(param_str);
SW_HASHTABLE_FOREACH_END();
}
redis_request(redis, params_num + 3, argv, argvlen, return_value);
efree(argvlen);
efree(argv);
}
static PHP_METHOD(swoole_redis_coro, script)
{
int argc = ZEND_NUM_ARGS();
if (argc < 1)
{
RETURN_FALSE
}
SW_REDIS_COMMAND_CHECK
SW_REDIS_COMMAND_ALLOC_ARGS_ARR
if (zend_get_parameters_array(ht, argc, z_args) == FAILURE || SW_REDIS_COMMAND_ARGS_TYPE(z_args[0]) != IS_STRING)
{
efree(z_args);
RETURN_FALSE;
}
int i = 0;
if (!strcasecmp(SW_REDIS_COMMAND_ARGS_STRVAL(z_args[0]), "flush")
|| !strcasecmp(SW_REDIS_COMMAND_ARGS_STRVAL(z_args[0]), "kill"))
{
size_t argvlen[2];
char *argv[2];
SW_REDIS_COMMAND_ARGV_FILL("SCRIPT", 6)
SW_REDIS_COMMAND_ARGV_FILL(SW_REDIS_COMMAND_ARGS_STRVAL(z_args[0]), SW_REDIS_COMMAND_ARGS_STRLEN(z_args[0]))
redis_request(redis, 2, argv, argvlen, return_value);
efree(z_args);
}
else if (!strcasecmp(SW_REDIS_COMMAND_ARGS_STRVAL(z_args[0]), "exists"))
{
if (argc < 2)
{
efree(z_args);
RETURN_FALSE
}
else
{
size_t *argvlen = (size_t *) emalloc(sizeof(size_t) * (argc + 1));
char **argv = (char **) emalloc(sizeof(char *) * (argc + 1));
SW_REDIS_COMMAND_ARGV_FILL("SCRIPT", 6)
SW_REDIS_COMMAND_ARGV_FILL("EXISTS", 6)
int j = 1;
for (; j < argc; j++)
{
zend_string *z_arg_str = zval_get_string(&z_args[j]);
SW_REDIS_COMMAND_ARGV_FILL(ZSTR_VAL(z_arg_str), ZSTR_LEN(z_arg_str))
zend_string_release(z_arg_str);
}
redis_request(redis, argc + 1, argv, argvlen, return_value);
efree(argvlen);
efree(argv);
efree(z_args);
}
}
else if (!strcasecmp(SW_REDIS_COMMAND_ARGS_STRVAL(z_args[0]), "load"))
{
if (argc < 2 || SW_REDIS_COMMAND_ARGS_TYPE(z_args[1]) != IS_STRING)
{
efree(z_args);
RETURN_FALSE
}
else
{
size_t argvlen[3];
char *argv[3];
SW_REDIS_COMMAND_ARGV_FILL("SCRIPT", 6)
SW_REDIS_COMMAND_ARGV_FILL("LOAD", 4)
SW_REDIS_COMMAND_ARGV_FILL(SW_REDIS_COMMAND_ARGS_STRVAL(z_args[1]), SW_REDIS_COMMAND_ARGS_STRLEN(z_args[1]))
redis_request(redis, 3, argv, argvlen, return_value);
efree(z_args);
}
}
else
{
efree(z_args);
RETURN_FALSE
}
}
static void swoole_redis_coro_parse_result(swRedisClient *redis, zval* return_value, redisReply* reply)
{
int j;
zval _val, *val = &_val;
switch (reply->type)
{
case REDIS_REPLY_INTEGER:
ZVAL_LONG(return_value, reply->integer);
break;
case REDIS_REPLY_ERROR:
ZVAL_FALSE(return_value);
if (redis->context->err == 0)
{
if (strncmp(reply->str, "NOAUTH", 6) == 0)
{
redis->context->err = SW_REDIS_ERR_NOAUTH;
}
else
{
redis->context->err = SW_REDIS_ERR_OTHER;
}
size_t str_len = strlen(reply->str);
memcpy(redis->context->errstr, reply->str, MIN(str_len, sizeof(redis->context->errstr)-1));
}
zend_update_property_long(swoole_redis_coro_ce, redis->zobject, ZEND_STRL("errType"), redis->context->err);
zend_update_property_long(swoole_redis_coro_ce, redis->zobject, ZEND_STRL("errCode"), sw_redis_convert_err(redis->context->err));
zend_update_property_string(swoole_redis_coro_ce, redis->zobject, ZEND_STRL("errMsg"), redis->context->errstr);
break;
case REDIS_REPLY_STATUS:
if (redis->context->err == 0)
{
if (reply->len > 0)
{
if (strncmp(reply->str, "OK", 2) == 0)
{
ZVAL_TRUE(return_value);
break;
}
long l;
if (strncmp(reply->str, "string", 6) == 0)
{
l = SW_REDIS_TYPE_STRING;
}
else if (strncmp(reply->str, "set", 3) == 0)
{
l = SW_REDIS_TYPE_SET;
}
else if (strncmp(reply->str, "list", 4) == 0)
{
l = SW_REDIS_TYPE_LIST;
}
else if (strncmp(reply->str, "zset", 4) == 0)
{
l = SW_REDIS_TYPE_ZSET;
}
else if (strncmp(reply->str, "hash", 4) == 0)
{
l = SW_REDIS_TYPE_HASH;
}
else
{
l = SW_REDIS_TYPE_NOT_FOUND;
}
ZVAL_LONG(return_value, l);
}
else
{
ZVAL_TRUE(return_value);
}
}
else
{
ZVAL_FALSE(return_value);
zend_update_property_long(swoole_redis_coro_ce, redis->zobject, ZEND_STRL("errType"), redis->context->err);
zend_update_property_long(swoole_redis_coro_ce, redis->zobject, ZEND_STRL("errCode"), sw_redis_convert_err(redis->context->err));
zend_update_property_string(swoole_redis_coro_ce, redis->zobject, ZEND_STRL("errMsg"), redis->context->errstr);
}
break;
case REDIS_REPLY_STRING:
if (redis->serialize)
{
char *reserve_str = reply->str;
php_unserialize_data_t s_ht;
PHP_VAR_UNSERIALIZE_INIT(s_ht);
if(!php_var_unserialize(return_value,
(const unsigned char**)&reply->str,
(const unsigned char*)reply->str + reply->len, &s_ht)) {
ZVAL_STRINGL(return_value, reply->str, reply->len);
}
PHP_VAR_UNSERIALIZE_DESTROY(s_ht);
reply->str = reserve_str;
}
else
{
ZVAL_STRINGL(return_value, reply->str, reply->len);
}
break;
case REDIS_REPLY_ARRAY:
array_init(return_value);
for (j = 0; j < (int) reply->elements; j++)
{
swoole_redis_coro_parse_result(redis, val, reply->element[j]);
(void) add_next_index_zval(return_value, val);
}
break;
case REDIS_REPLY_NIL:
default:
ZVAL_NULL(return_value);
return;
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/whoneed/swoole.git
git@gitee.com:whoneed/swoole.git
whoneed
swoole
swoole-src
master

搜索帮助