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.util.Slowlog;
13
14 import hunt.redis.util.SafeEncoder;
15
16 import hunt.collection.ArrayList;
17 import hunt.collection.List;
18 import hunt.Long;
19 import hunt.util.StringBuilder;
20
21 /**
22 *
23 */
24 class Slowlog {
25 private long id;
26 private long timeStamp;
27 private long executionTime;
28 private List!(string) args;
29 private enum string COMMA = ",";
30
31 private this(List!(Object) properties) {
32 this.id = (cast(Long) properties.get(0)).value();
33 this.timeStamp = (cast(Long) properties.get(1)).value();
34 this.executionTime = (cast(Long) properties.get(2)).value();
35
36 List!(string) bargs = cast(List!(string)) properties.get(3);
37 this.args = new ArrayList!(string)(bargs.size());
38
39 foreach (string barg; bargs) {
40 this.args.add(barg);
41 }
42 }
43
44 static List!(Slowlog) from(List!(Object) nestedMultiBulkReply) {
45 List!(Slowlog) logs = new ArrayList!(Slowlog)(nestedMultiBulkReply.size());
46 foreach (Object obj; nestedMultiBulkReply) {
47 List!(Object) properties = cast(List!(Object)) obj;
48 logs.add(new Slowlog(properties));
49 }
50
51 return logs;
52 }
53
54 long getId() {
55 return id;
56 }
57
58 long getTimeStamp() {
59 return timeStamp;
60 }
61
62 long getExecutionTime() {
63 return executionTime;
64 }
65
66 List!(string) getArgs() {
67 return args;
68 }
69
70 override string toString() {
71 return new StringBuilder().append(id).append(COMMA).append(timeStamp)
72 .append(COMMA).append(executionTime).append(COMMA)
73 .append((cast(Object) args).toString()).toString();
74 }
75 }