1 /*
2  * Hunt - A redis client library for D programming language.
3  *
4  * Copyright (C) 2018-2019 HuntLabs
5  *
6  * Website: https://www.huntlabs.net/
7  *
8  * Licensed under the Apache-2.0 License.
9  *
10  */
11  
12 module hunt.redis.MultiKeyPipelineBase;
13 
14 import hunt.redis.commands;
15 import hunt.redis.BinaryRedis;
16 import hunt.redis.BuilderFactory;
17 import hunt.redis.Client;
18 import hunt.redis.BitOP;
19 import hunt.redis.Client;
20 import hunt.redis.GeoCoordinate;
21 import hunt.redis.GeoRadiusResponse;
22 import hunt.redis.GeoUnit;
23 import hunt.redis.ListPosition;
24 import hunt.redis.Module;
25 import hunt.redis.PipelineBase;
26 import hunt.redis.Redis;
27 import hunt.redis.Response;
28 import hunt.redis.SortingParams;
29 import hunt.redis.ZParams;
30 import hunt.redis.params.MigrateParams;
31 
32 import hunt.collection.List;
33 import hunt.collection.Map;
34 import hunt.collection.Set;
35 
36 import hunt.Boolean;
37 import hunt.Double;
38 import hunt.Long;
39 
40 abstract class MultiKeyPipelineBase : PipelineBase,
41         MultiKeyBinaryRedisPipeline, MultiKeyCommandsPipeline, ClusterPipeline,
42         BinaryScriptingCommandsPipeline, ScriptingCommandsPipeline, BasicRedisPipeline {
43 
44     protected Client client = null;
45 
46     Response!(List!(string)) brpop(string[] args...) {
47         client.brpop(args);
48         return getResponse(BuilderFactory.STRING_LIST);
49     }
50     alias brpop = PipelineBase.brpop;
51 
52     Response!(List!(string)) brpop(int timeout, string[] keys...) {
53         client.brpop(timeout, keys);
54         return getResponse(BuilderFactory.STRING_LIST);
55     }
56 
57     Response!(List!(string)) blpop(string[] args...) {
58         client.blpop(args);
59         return getResponse(BuilderFactory.STRING_LIST);
60     }
61     alias blpop = PipelineBase.blpop;
62 
63     Response!(List!(string)) blpop(int timeout, string[] keys...) {
64         client.blpop(timeout, keys);
65         return getResponse(BuilderFactory.STRING_LIST);
66     }
67 
68     Response!(Map!(string, string)) blpopMap(int timeout, string[] keys...) {
69         client.blpop(timeout, keys);
70         return getResponse(BuilderFactory.STRING_MAP);
71     }
72 
73     override
74     Response!(List!(const(ubyte)[])) brpop(const(ubyte)[][] args...) {
75         client.brpop(args);
76         return getResponse(BuilderFactory.BYTE_ARRAY_LIST);
77     }
78 
79     Response!(List!(string)) brpop(int timeout, const(ubyte)[][] keys...) {
80         client.brpop(timeout, keys);
81         return getResponse(BuilderFactory.STRING_LIST);
82     }
83 
84     Response!(Map!(string, string)) brpopMap(int timeout, string[] keys...) {
85         client.blpop(timeout, keys);
86         return getResponse(BuilderFactory.STRING_MAP);
87     }
88 
89     override
90     Response!(List!(const(ubyte)[])) blpop(const(ubyte)[][] args...) {
91         client.blpop(args);
92         return getResponse(BuilderFactory.BYTE_ARRAY_LIST);
93     }
94 
95     Response!(List!(string)) blpop(int timeout, const(ubyte)[][] keys...) {
96         client.blpop(timeout, keys);
97         return getResponse(BuilderFactory.STRING_LIST);
98     }
99 
100     Response!(Long) del(string[] keys...) {
101         client.del(keys);
102         return getResponse(BuilderFactory.LONG);
103     }
104     alias del = PipelineBase.del;
105 
106     Response!(Long) del(const(ubyte)[][] keys...) {
107         client.del(keys);
108         return getResponse(BuilderFactory.LONG);
109     }
110 
111     Response!(Long) unlink(string[] keys...) {
112         client.unlink(keys);
113         return getResponse(BuilderFactory.LONG);
114     }
115     alias unlink = PipelineBase.unlink;
116 
117     Response!(Long) unlink(const(ubyte)[][] keys...) {
118         client.unlink(keys);
119         return getResponse(BuilderFactory.LONG);
120     }
121 
122     Response!(Long) exists(string[] keys...) {
123         client.exists(keys);
124         return getResponse(BuilderFactory.LONG);
125     }
126     alias exists = PipelineBase.exists;
127 
128     Response!(Long) exists(const(ubyte)[][] keys...) {
129         client.exists(keys);
130         return getResponse(BuilderFactory.LONG);
131     }
132 
133     override
134     Response!(Set!(string)) keys(string pattern) {
135         getClient(pattern).keys(pattern);
136         return getResponse(BuilderFactory.STRING_SET);
137     }
138 
139     override
140     Response!(Set!(const(ubyte)[])) keys(const(ubyte)[] pattern) {
141         getClient(pattern).keys(pattern);
142         return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
143     }
144 
145     override
146     Response!(List!(string)) mget(string[] keys...) {
147         client.mget(keys);
148         return getResponse(BuilderFactory.STRING_LIST);
149     }
150 
151     override
152     Response!(List!(const(ubyte)[])) mget(const(ubyte)[][] keys...) {
153         client.mget(keys);
154         return getResponse(BuilderFactory.BYTE_ARRAY_LIST);
155     }
156 
157     override
158     Response!(string) mset(string[] keysvalues...) {
159         client.mset(keysvalues);
160         return getResponse(BuilderFactory.STRING);
161     }
162 
163     override
164     Response!(string) mset(const(ubyte)[][] keysvalues...) {
165         client.mset(keysvalues);
166         return getResponse(BuilderFactory.STRING);
167     }
168 
169     override
170     Response!(Long) msetnx(string[] keysvalues...) {
171         client.msetnx(keysvalues);
172         return getResponse(BuilderFactory.LONG);
173     }
174 
175     override
176     Response!(Long) msetnx(const(ubyte)[][] keysvalues...) {
177         client.msetnx(keysvalues);
178         return getResponse(BuilderFactory.LONG);
179     }
180 
181     override
182     Response!(string) rename(string oldkey, string newkey) {
183         client.rename(oldkey, newkey);
184         return getResponse(BuilderFactory.STRING);
185     }
186 
187     override
188     Response!(string) rename(const(ubyte)[] oldkey, const(ubyte)[] newkey) {
189         client.rename(oldkey, newkey);
190         return getResponse(BuilderFactory.STRING);
191     }
192 
193     override
194     Response!(Long) renamenx(string oldkey, string newkey) {
195         client.renamenx(oldkey, newkey);
196         return getResponse(BuilderFactory.LONG);
197     }
198 
199     override
200     Response!(Long) renamenx(const(ubyte)[] oldkey, const(ubyte)[] newkey) {
201         client.renamenx(oldkey, newkey);
202         return getResponse(BuilderFactory.LONG);
203     }
204 
205     override
206     Response!(string) rpoplpush(string srckey, string dstkey) {
207         client.rpoplpush(srckey, dstkey);
208         return getResponse(BuilderFactory.STRING);
209     }
210 
211     override
212     Response!(const(ubyte)[]) rpoplpush(const(ubyte)[] srckey, const(ubyte)[] dstkey) {
213         client.rpoplpush(srckey, dstkey);
214         return getResponse(BuilderFactory.BYTE_ARRAY);
215     }
216 
217     override
218     Response!(Set!(string)) sdiff(string[] keys...) {
219         client.sdiff(keys);
220         return getResponse(BuilderFactory.STRING_SET);
221     }
222 
223     override
224     Response!(Set!(const(ubyte)[])) sdiff(const(ubyte)[][] keys...) {
225         client.sdiff(keys);
226         return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
227     }
228 
229     override
230     Response!(Long) sdiffstore(string dstkey, string[] keys...) {
231         client.sdiffstore(dstkey, keys);
232         return getResponse(BuilderFactory.LONG);
233     }
234 
235     override
236     Response!(Long) sdiffstore(const(ubyte)[] dstkey, const(ubyte)[][] keys...) {
237         client.sdiffstore(dstkey, keys);
238         return getResponse(BuilderFactory.LONG);
239     }
240 
241     override
242     Response!(Set!(string)) sinter(string[] keys...) {
243         client.sinter(keys);
244         return getResponse(BuilderFactory.STRING_SET);
245     }
246 
247     override
248     Response!(Set!(const(ubyte)[])) sinter(const(ubyte)[][] keys...) {
249         client.sinter(keys);
250         return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
251     }
252 
253     override
254     Response!(Long) sinterstore(string dstkey, string[] keys...) {
255         client.sinterstore(dstkey, keys);
256         return getResponse(BuilderFactory.LONG);
257     }
258 
259     override
260     Response!(Long) sinterstore(const(ubyte)[] dstkey, const(ubyte)[][] keys...) {
261         client.sinterstore(dstkey, keys);
262         return getResponse(BuilderFactory.LONG);
263     }
264 
265     override
266     Response!(Long) smove(string srckey, string dstkey, string member) {
267         client.smove(srckey, dstkey, member);
268         return getResponse(BuilderFactory.LONG);
269     }
270 
271     override
272     Response!(Long) smove(const(ubyte)[] srckey, const(ubyte)[] dstkey, const(ubyte)[] member) {
273         client.smove(srckey, dstkey, member);
274         return getResponse(BuilderFactory.LONG);
275     }
276 
277     override
278     Response!(Long) sort(string key, SortingParams sortingParameters, string dstkey) {
279         client.sort(key, sortingParameters, dstkey);
280         return getResponse(BuilderFactory.LONG);
281     }
282 
283     override
284     Response!(Long) sort(const(ubyte)[] key, SortingParams sortingParameters, const(ubyte)[] dstkey) {
285         client.sort(key, sortingParameters, dstkey);
286         return getResponse(BuilderFactory.LONG);
287     }
288 
289     override
290     Response!(Long) sort(string key, string dstkey) {
291         client.sort(key, dstkey);
292         return getResponse(BuilderFactory.LONG);
293     }
294 
295     override
296     Response!(Long) sort(const(ubyte)[] key, const(ubyte)[] dstkey) {
297         client.sort(key, dstkey);
298         return getResponse(BuilderFactory.LONG);
299     }
300 
301     override
302     Response!(Set!(string)) sunion(string[] keys...) {
303         client.sunion(keys);
304         return getResponse(BuilderFactory.STRING_SET);
305     }
306 
307     override
308     Response!(Set!(const(ubyte)[])) sunion(const(ubyte)[][] keys...) {
309         client.sunion(keys);
310         return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
311     }
312 
313     override
314     Response!(Long) sunionstore(string dstkey, string[] keys...) {
315         client.sunionstore(dstkey, keys);
316         return getResponse(BuilderFactory.LONG);
317     }
318 
319     override
320     Response!(Long) sunionstore(const(ubyte)[] dstkey, const(ubyte)[][] keys...) {
321         client.sunionstore(dstkey, keys);
322         return getResponse(BuilderFactory.LONG);
323     }
324 
325     override
326     Response!(string) watch(string[] keys...) {
327         client.watch(keys);
328         return getResponse(BuilderFactory.STRING);
329     }
330 
331     override
332     Response!(string) watch(const(ubyte)[][] keys...) {
333         client.watch(keys);
334         return getResponse(BuilderFactory.STRING);
335     }
336 
337     override
338     Response!(Long) zinterstore(string dstkey, string[] sets...) {
339         client.zinterstore(dstkey, sets);
340         return getResponse(BuilderFactory.LONG);
341     }
342 
343     override
344     Response!(Long) zinterstore(const(ubyte)[] dstkey, const(ubyte)[][] sets...) {
345         client.zinterstore(dstkey, sets);
346         return getResponse(BuilderFactory.LONG);
347     }
348 
349     override
350     Response!(Long) zinterstore(string dstkey, ZParams params, string[] sets...) {
351         client.zinterstore(dstkey, params, sets);
352         return getResponse(BuilderFactory.LONG);
353     }
354 
355     override
356     Response!(Long) zinterstore(const(ubyte)[] dstkey, ZParams params, const(ubyte)[][] sets...) {
357         client.zinterstore(dstkey, params, sets);
358         return getResponse(BuilderFactory.LONG);
359     }
360 
361     override
362     Response!(Long) zunionstore(string dstkey, string[] sets...) {
363         client.zunionstore(dstkey, sets);
364         return getResponse(BuilderFactory.LONG);
365     }
366 
367     override
368     Response!(Long) zunionstore(const(ubyte)[] dstkey, const(ubyte)[][] sets...) {
369         client.zunionstore(dstkey, sets);
370         return getResponse(BuilderFactory.LONG);
371     }
372 
373     override
374     Response!(Long) zunionstore(string dstkey, ZParams params, string[] sets...) {
375         client.zunionstore(dstkey, params, sets);
376         return getResponse(BuilderFactory.LONG);
377     }
378 
379     override
380     Response!(Long) zunionstore(const(ubyte)[] dstkey, ZParams params, const(ubyte)[][] sets...) {
381         client.zunionstore(dstkey, params, sets);
382         return getResponse(BuilderFactory.LONG);
383     }
384 
385     override
386     Response!(string) bgrewriteaof() {
387         client.bgrewriteaof();
388         return getResponse(BuilderFactory.STRING);
389     }
390 
391     override
392     Response!(string) bgsave() {
393         client.bgsave();
394         return getResponse(BuilderFactory.STRING);
395     }
396 
397     override
398     Response!(List!(string)) configGet(string pattern) {
399         client.configGet(pattern);
400         return getResponse(BuilderFactory.STRING_LIST);
401     }
402 
403     override
404     Response!(string) configSet(string parameter, string value) {
405         client.configSet(parameter, value);
406         return getResponse(BuilderFactory.STRING);
407     }
408 
409     override
410     Response!(string) brpoplpush(string source, string destination, int timeout) {
411         client.brpoplpush(source, destination, timeout);
412         return getResponse(BuilderFactory.STRING);
413     }
414 
415     override
416     Response!(const(ubyte)[]) brpoplpush(const(ubyte)[] source, const(ubyte)[] destination, int timeout) {
417         client.brpoplpush(source, destination, timeout);
418         return getResponse(BuilderFactory.BYTE_ARRAY);
419     }
420 
421     override
422     Response!(string) configResetStat() {
423         client.configResetStat();
424         return getResponse(BuilderFactory.STRING);
425     }
426 
427     override
428     Response!(string) save() {
429         client.save();
430         return getResponse(BuilderFactory.STRING);
431     }
432 
433     override
434     Response!(Long) lastsave() {
435         client.lastsave();
436         return getResponse(BuilderFactory.LONG);
437     }
438 
439     override
440     Response!(Long) publish(string channel, string message) {
441         client.publish(channel, message);
442         return getResponse(BuilderFactory.LONG);
443     }
444 
445     override
446     Response!(Long) publish(const(ubyte)[] channel, const(ubyte)[] message) {
447         client.publish(channel, message);
448         return getResponse(BuilderFactory.LONG);
449     }
450 
451     override
452     Response!(string) randomKey() {
453         client.randomKey();
454         return getResponse(BuilderFactory.STRING);
455     }
456 
457     override
458     Response!(const(ubyte)[]) randomKeyBinary() {
459         client.randomKey();
460         return getResponse(BuilderFactory.BYTE_ARRAY);
461     }
462 
463     override
464     Response!(string) flushDB() {
465         client.flushDB();
466         return getResponse(BuilderFactory.STRING);
467     }
468 
469     override
470     Response!(string) flushAll() {
471         client.flushAll();
472         return getResponse(BuilderFactory.STRING);
473     }
474 
475     override
476     Response!(string) info() {
477         client.info();
478         return getResponse(BuilderFactory.STRING);
479     }
480 
481     Response!(string) info(string section) {
482         client.info(section);
483         return getResponse(BuilderFactory.STRING);
484     }
485 
486     override
487     Response!(Long) dbSize() {
488         client.dbSize();
489         return getResponse(BuilderFactory.LONG);
490     }
491 
492     override
493     Response!(string) shutdown() {
494         client.shutdown();
495         return getResponse(BuilderFactory.STRING);
496     }
497 
498     override
499     Response!(string) ping() {
500         client.ping();
501         return getResponse(BuilderFactory.STRING);
502     }
503 
504     override
505     Response!(string) select(int index) {
506         client.select(index);
507         Response!(string) response = getResponse(BuilderFactory.STRING);
508         client.setDb(index);
509 
510         return response;
511     }
512 
513     override
514     Response!(string) swapDB(int index1, int index2) {
515         client.swapDB(index1, index2);
516         return getResponse(BuilderFactory.STRING);
517     }
518 
519     override
520     Response!(Long) bitop(BitOP op, const(ubyte)[] destKey, const(ubyte)[][] srcKeys...) {
521         client.bitop(op, destKey, srcKeys);
522         return getResponse(BuilderFactory.LONG);
523     }
524 
525     override
526     Response!(Long) bitop(BitOP op, string destKey, string[] srcKeys...) {
527         client.bitop(op, destKey, srcKeys);
528         return getResponse(BuilderFactory.LONG);
529     }
530 
531     override
532     Response!(string) clusterNodes() {
533         client.clusterNodes();
534         return getResponse(BuilderFactory.STRING);
535     }
536 
537     override
538     Response!(string) clusterMeet(string ip, int port) {
539         client.clusterMeet(ip, port);
540         return getResponse(BuilderFactory.STRING);
541     }
542 
543     override
544     Response!(string) clusterAddSlots(int[] slots...) {
545         client.clusterAddSlots(slots);
546         return getResponse(BuilderFactory.STRING);
547     }
548 
549     override
550     Response!(string) clusterDelSlots(int[] slots...) {
551         client.clusterDelSlots(slots);
552         return getResponse(BuilderFactory.STRING);
553     }
554 
555     override
556     Response!(string) clusterInfo() {
557         client.clusterInfo();
558         return getResponse(BuilderFactory.STRING);
559     }
560 
561     override
562     Response!(List!(string)) clusterGetKeysInSlot(int slot, int count) {
563         client.clusterGetKeysInSlot(slot, count);
564         return getResponse(BuilderFactory.STRING_LIST);
565     }
566 
567     override
568     Response!(string) clusterSetSlotNode(int slot, string nodeId) {
569         client.clusterSetSlotNode(slot, nodeId);
570         return getResponse(BuilderFactory.STRING);
571     }
572 
573     override
574     Response!(string) clusterSetSlotMigrating(int slot, string nodeId) {
575         client.clusterSetSlotMigrating(slot, nodeId);
576         return getResponse(BuilderFactory.STRING);
577     }
578 
579     override
580     Response!(string) clusterSetSlotImporting(int slot, string nodeId) {
581         client.clusterSetSlotImporting(slot, nodeId);
582         return getResponse(BuilderFactory.STRING);
583     }
584 
585     override
586     Response!(Object) eval(string script) {
587         return this.eval(script, 0, new string[0]);
588     }
589 
590     override
591     Response!(Object) eval(string script, List!(string) keys, List!(string) args) {
592         string[] argv = Redis.getParams(keys, args);
593         return this.eval(script, keys.size(), argv);
594     }
595 
596     override
597     Response!(Object) eval(string script, int keyCount, string[] params...) {
598         getClient(script).eval(script, keyCount, params);
599         return getResponse(BuilderFactory.EVAL_RESULT);
600     }
601 
602     override
603     Response!(Object) evalsha(string sha1) {
604         return this.evalsha(sha1, 0, new string[0]);
605     }
606 
607     override
608     Response!(Object) evalsha(string sha1, List!(string) keys, List!(string) args) {
609         string[] argv = Redis.getParams(keys, args);
610         return this.evalsha(sha1, keys.size(), argv);
611     }
612 
613     override
614     Response!(Object) evalsha(string sha1, int keyCount, string[] params...) {
615         getClient(sha1).evalsha(sha1, keyCount, params);
616         return getResponse(BuilderFactory.EVAL_RESULT);
617     }
618 
619     override
620     Response!(Object) eval(const(ubyte)[] script) {
621         return this.eval(script, 0);
622     }
623 
624     override
625     Response!(Object) eval(const(ubyte)[] script, const(ubyte)[] keyCount, const(ubyte)[][] params...) {
626         getClient(script).eval(script, keyCount, params);
627         return getResponse(BuilderFactory.EVAL_BINARY_RESULT);
628     }
629 
630     override
631     Response!(Object) eval(const(ubyte)[] script, List!(const(ubyte)[]) keys, List!(const(ubyte)[]) args) {
632         const(ubyte)[][] argv = BinaryRedis.getParamsWithBinary(keys, args);
633         return this.eval(script, keys.size(), argv);
634     }
635 
636     override
637     Response!(Object) eval(const(ubyte)[] script, int keyCount, const(ubyte)[][] params...) {
638         getClient(script).eval(script, keyCount, params);
639         return getResponse(BuilderFactory.EVAL_BINARY_RESULT);
640     }
641 
642     override
643     Response!(Object) evalsha(const(ubyte)[] sha1) {
644         return this.evalsha(sha1, 0);
645     }
646 
647     override
648     Response!(Object) evalsha(const(ubyte)[] sha1, List!(const(ubyte)[]) keys, List!(const(ubyte)[]) args) {
649         const(ubyte)[][] argv = BinaryRedis.getParamsWithBinary(keys, args);
650         return this.evalsha(sha1, keys.size(), argv);
651     }
652 
653     override
654     Response!(Object) evalsha(const(ubyte)[] sha1, int keyCount, const(ubyte)[][] params...) {
655         getClient(sha1).evalsha(sha1, keyCount, params);
656         return getResponse(BuilderFactory.EVAL_BINARY_RESULT);
657     }
658 
659     Response!(Long) pfcount(string[] keys...) {
660         client.pfcount(keys);
661         return getResponse(BuilderFactory.LONG);
662     }
663     alias pfcount = PipelineBase.pfcount;
664 
665     Response!(Long) pfcount(const(ubyte)[][] keys...) {
666         client.pfcount(keys);
667         return getResponse(BuilderFactory.LONG);
668     }
669 
670     override
671     Response!(string) pfmerge(const(ubyte)[] destkey, const(ubyte)[][] sourcekeys...) {
672         client.pfmerge(destkey, sourcekeys);
673         return getResponse(BuilderFactory.STRING);
674     }
675 
676     override
677     Response!(string) pfmerge(string destkey, string[] sourcekeys...) {
678         client.pfmerge(destkey, sourcekeys);
679         return getResponse(BuilderFactory.STRING);
680     }
681 
682     override
683     Response!(List!(string)) time() {
684         client.time();
685         return getResponse(BuilderFactory.STRING_LIST);
686     }
687 
688     Response!(Long) touch(string[] keys...) {
689         client.touch(keys);
690         return getResponse(BuilderFactory.LONG);
691     }
692     alias touch = PipelineBase.touch;
693 
694     Response!(Long) touch(const(ubyte)[][] keys...) {
695         client.touch(keys);
696         return getResponse(BuilderFactory.LONG);
697     }
698 
699     override
700     Response!(string) moduleUnload(string name) {
701         client.moduleUnload(name);
702         return getResponse(BuilderFactory.STRING);
703     }
704 
705     override
706     Response!(List!(Module)) moduleList() {
707         client.moduleList();
708         return getResponse(BuilderFactory.MODULE_LIST);
709     }
710 
711     override
712     Response!(string) moduleLoad(string path) {
713         client.moduleLoad(path);
714         return getResponse(BuilderFactory.STRING);
715     }  
716     
717     Response!(string) migrate(string host, int port, int destinationDB,
718             int timeout, MigrateParams params, string[] keys...) {
719         client.migrate(host, port, destinationDB, timeout, params, keys);
720         return getResponse(BuilderFactory.STRING);
721     }
722     alias migrate = PipelineBase.migrate;
723 
724     Response!(string) migrate(string host, int port, int destinationDB,
725             int timeout, MigrateParams params, const(ubyte)[][] keys...) {
726         client.migrate(host, port, destinationDB, timeout, params, keys);
727         return getResponse(BuilderFactory.STRING);
728     }
729 
730     override Response!string migrate(string host, int port, string key, int destinationDB, int timeout) {
731         return super.migrate(host, port, key, destinationDB, timeout);
732     }
733 
734     override
735     Response!(Object) sendCommand(ProtocolCommand cmd, string[] args...){
736         client.sendCommand(cmd, args);
737         return getResponse(BuilderFactory.OBJECT);
738     }
739     
740 }