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.ZParams; 13 14 // import hunt.redis.Protocol.Keyword.AGGREGATE; 15 // import hunt.redis.Protocol.Keyword.WEIGHTS; 16 17 import hunt.redis.Protocol; 18 19 import hunt.collection.ArrayList; 20 import hunt.collection.Collection; 21 import hunt.collection.Collections; 22 import hunt.collection.List; 23 24 import std.conv; 25 26 import hunt.redis.util.SafeEncoder; 27 28 enum Aggregate { 29 SUM, 30 MIN, 31 MAX 32 } 33 34 class ZParams { 35 36 private List!(const(ubyte)[]) params; 37 38 this() { 39 params = new ArrayList!(const(ubyte)[])(); 40 } 41 42 /** 43 * Set weights. 44 * @param weights weights. 45 * @return 46 */ 47 ZParams weights(double[] weights...) { 48 params.add(SafeEncoder.encode(Protocol.Keyword.WEIGHTS.to!string())); 49 foreach (double weight; weights) { 50 params.add(Protocol.toByteArray(weight)); 51 } 52 53 return this; 54 } 55 56 Collection!(const(ubyte)[]) getParams() { 57 return params; // Collections.unmodifiableCollection(params); 58 } 59 60 ZParams aggregate(Aggregate aggregate) { 61 params.add(SafeEncoder.encode(Protocol.Keyword.AGGREGATE.to!string())); 62 params.add(SafeEncoder.encode(aggregate.to!string())); 63 return this; 64 } 65 }