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.params.ZAddParams; 13 14 import hunt.redis.params.Params; 15 16 import hunt.redis.util.SafeEncoder; 17 18 import hunt.collection.ArrayList; 19 20 class ZAddParams : Params { 21 22 private enum string XX = "xx"; 23 private enum string NX = "nx"; 24 private enum string CH = "ch"; 25 26 this() { 27 } 28 29 static ZAddParams zAddParams() { 30 return new ZAddParams(); 31 } 32 33 /** 34 * Only set the key if it does not already exist. 35 * @return ZAddParams 36 */ 37 ZAddParams nx() { 38 addParam(NX); 39 return this; 40 } 41 42 /** 43 * Only set the key if it already exist. 44 * @return ZAddParams 45 */ 46 ZAddParams xx() { 47 addParam(XX); 48 return this; 49 } 50 51 /** 52 * Modify the return value from the number of new elements added to the total number of elements 53 * changed 54 * @return ZAddParams 55 */ 56 ZAddParams ch() { 57 addParam(CH); 58 return this; 59 } 60 61 const(ubyte)[][] getByteParams(const(ubyte)[] key, const(ubyte)[][] args...) { 62 ArrayList!(const(ubyte)[]) byteParams = new ArrayList!(const(ubyte)[])(); 63 byteParams.add(key); 64 65 if (contains(NX)) { 66 byteParams.add(SafeEncoder.encode(NX)); 67 } 68 if (contains(XX)) { 69 byteParams.add(SafeEncoder.encode(XX)); 70 } 71 if (contains(CH)) { 72 byteParams.add(SafeEncoder.encode(CH)); 73 } 74 75 foreach (const(ubyte)[] arg; args) { 76 byteParams.add(arg); 77 } 78 79 return byteParams.toArray(); 80 } 81 82 }