Metrics
0
Watch 281 Star 1.1K Fork 250

GVPswoole / swoole-srcCApache-2.0

Sign up for free
Explore and code with more than 2 million developers,Free private repositories !:)
Sign up
PHP的异步、并行、高性能网络通信引擎 spread retract

http://www.swoole.com/

  • C++ 38.3%
  • PHP 35.8%
  • C 24.8%
  • M4 0.5%
  • Shell 0.2%
  • Other 0.4%
Clone or download
swoole_redis_coro.cc 151.91 KB
Copy Edit Web IDE Raw Blame History
韩天峰 authored 2019-06-18 21:38 . fix tests
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693
/*
+----------------------------------------------------------------------+
| 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 "thirdparty/hiredis/hiredis.h"
#include "thirdparty/hiredis/async.h"
#include "ext/standard/php_var.h"
using namespace swoole;
using swoole::coroutine::Socket;
#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;
bool compatibility_mode;
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))
{
php_swoole_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 && SwooleG.main_reactor)
{
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 sw_inline void swoole_redis_handle_assoc_array_result(zval* return_value, bool str2double) {
zval *zkey, *zvalue;
zval zret;
bool is_key = false;
array_init(&zret);
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(return_value), zvalue)
{
if((is_key = !is_key))
{
zkey = zvalue;
}
else
{
if(str2double)
{
convert_to_double(zvalue);
}
else
{
Z_ADDREF_P(zvalue);
}
add_assoc_zval_ex(&zret, Z_STRVAL_P(zkey), Z_STRLEN_P(zkey), zvalue);
}
}
ZEND_HASH_FOREACH_END();
zval_ptr_dtor(return_value);
RETVAL_ZVAL(&zret, 1, 1);
}
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)
{
php_swoole_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)
{
php_swoole_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_and_convert_property_array(swoole_redis_coro_ce, redis->zobject, ZEND_STRL("setting"), 0);
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);
if (redis->compatibility_mode)
{
if (ZVAL_IS_ARRAY(return_value) && memcmp("HGETALL", cmd, cmd_len) == 0)
{
swoole_redis_handle_assoc_array_result(return_value, false);
}
else if (ZVAL_IS_NULL(return_value) && memcmp("GET", cmd, cmd_len) == 0)
{
RETURN_FALSE;
}
}
}
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);
if (redis->compatibility_mode && ZVAL_IS_NULL(return_value) && memcmp("ZRANK", cmd, cmd_len) == 0)
{
RETURN_FALSE;
}
}
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, sw_zend_class_clone_deny);
SW_SET_CLASS_UNSET_PROPERTY_HANDLER(swoole_redis_coro, sw_zend_class_unset_property_deny);
SW_SET_CLASS_CREATE_WITH_ITS_OWN_HANDLERS(swoole_redis_coro);
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_and_convert_property_array(swoole_redis_coro_ce, redis->zobject, ZEND_STRL("setting"), 0);
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) SW_MIN(zval_get_long(ztmp), UINT8_MAX);
}
if (php_swoole_array_get_value(vht, "compatibility_mode", ztmp))
{
redis->compatibility_mode = zval_is_true(ztmp);
}
}
static PHP_METHOD(swoole_redis_coro, __construct)
{
swRedisClient *redis = (swRedisClient *) swoole_get_object(getThis());
zval *zsettings = sw_zend_read_and_convert_property_array(swoole_redis_coro_ce, getThis(), ZEND_STRL("setting"), 0);
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)
{
php_swoole_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_and_convert_property_array(swoole_redis_coro_ce, getThis(), ZEND_STRL("setting"), 0);
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_and_convert_property_array(swoole_redis_coro_ce, getThis(), ZEND_STRL("setting"), 0), 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)
{
php_swoole_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))
{
php_swoole_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 (!ZVAL_IS_ARRAY(return_value))
{
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 && ZVAL_IS_ARRAY(z_opts))
{
HashTable *kt = Z_ARRVAL_P(z_opts);
zend_string *zkey;
zend_ulong idx;
zval *zv;
/* Iterate our option array */
ZEND_HASH_FOREACH_KEY_VAL(kt, idx, zkey, zv)
{
/* 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(zv) == IS_LONG)
{
expire = Z_LVAL_P(zv);
}
else if (Z_TYPE_P(zv) == IS_STRING)
{
expire = atol(Z_STRVAL_P(zv));
}
/* Expiry can't be set < 1 */
if (expire < 1)
{
RETURN_FALSE;
}
argc += 2;
}
else if (!set_type && Z_TYPE_P(zv) == IS_STRING && IS_NX_XX_ARG(Z_STRVAL_P(zv)))
{
argc += 1;
set_type = Z_STRVAL_P(zv);
}
(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_and_convert_property_array(swoole_redis_coro_ce, getThis(), ZEND_STRL("setting"), 0);
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);
if (ws && redis->compatibility_mode && ZVAL_IS_ARRAY(return_value))
{
swoole_redis_handle_assoc_array_result(return_value, true);
}
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)