|
10 | 10 | // |
11 | 11 |
|
12 | 12 | using System; |
| 13 | +using System.Collections.Generic; |
13 | 14 | using System.Diagnostics; |
14 | 15 | using System.Globalization; |
15 | 16 | using System.IO; |
@@ -114,6 +115,9 @@ private void Connect() |
114 | 115 | if (db != 0) |
115 | 116 | SendExpectSuccess(Commands.Select, db.ToUtf8Bytes()); |
116 | 117 |
|
| 118 | + if (Client != null) |
| 119 | + SendExpectSuccess(Commands.Client, Commands.SetName, Client.ToUtf8Bytes()); |
| 120 | + |
117 | 121 | try |
118 | 122 | { |
119 | 123 | if (ServerVersionNumber == 0) |
@@ -527,6 +531,19 @@ protected object[] SendExpectDeeplyNestedMultiData(params byte[][] cmdWithBinary |
527 | 531 | return ReadDeeplyNestedMultiData(); |
528 | 532 | } |
529 | 533 |
|
| 534 | + protected RedisData SendExpectComplexResponse(params byte[][] cmdWithBinaryArgs) |
| 535 | + { |
| 536 | + if (!SendCommand(cmdWithBinaryArgs)) |
| 537 | + throw CreateConnectionError(); |
| 538 | + |
| 539 | + if (Pipeline != null) |
| 540 | + { |
| 541 | + throw new NotSupportedException("Pipeline is not supported."); |
| 542 | + } |
| 543 | + |
| 544 | + return ReadComplexResponse(); |
| 545 | + } |
| 546 | + |
530 | 547 | protected void Log(string fmt, params object[] args) |
531 | 548 | { |
532 | 549 | log.DebugFormat("{0}", string.Format(fmt, args).Trim()); |
@@ -802,6 +819,47 @@ private object ReadDeeplyNestedMultiDataItem() |
802 | 819 | throw CreateResponseError("Unknown reply on multi-request: " + c + s); |
803 | 820 | } |
804 | 821 |
|
| 822 | + internal RedisData ReadComplexResponse() |
| 823 | + { |
| 824 | + int c = SafeReadByte(); |
| 825 | + if (c == -1) |
| 826 | + throw CreateResponseError("No more data"); |
| 827 | + |
| 828 | + var s = ReadLine(); |
| 829 | + if (log.IsDebugEnabled) |
| 830 | + Log("R: {0}", s); |
| 831 | + |
| 832 | + switch (c) |
| 833 | + { |
| 834 | + case '$': |
| 835 | + return new RedisData { |
| 836 | + Data = ParseSingleLine(string.Concat(char.ToString((char) c), s)) |
| 837 | + }; |
| 838 | + |
| 839 | + case '-': |
| 840 | + throw CreateResponseError(s.StartsWith("ERR") ? s.Substring(4) : s); |
| 841 | + |
| 842 | + case '*': |
| 843 | + int count; |
| 844 | + if (int.TryParse(s, out count)) |
| 845 | + { |
| 846 | + var ret = new RedisData { Children = new List<RedisData>() }; |
| 847 | + for (var i = 0; i < count; i++) |
| 848 | + { |
| 849 | + ret.Children.Add(ReadComplexResponse()); |
| 850 | + } |
| 851 | + |
| 852 | + return ret; |
| 853 | + } |
| 854 | + break; |
| 855 | + |
| 856 | + default: |
| 857 | + return new RedisData { Data = s.ToUtf8Bytes() }; |
| 858 | + } |
| 859 | + |
| 860 | + throw CreateResponseError("Unknown reply on multi-request: " + c + s); |
| 861 | + } |
| 862 | + |
805 | 863 | internal int ReadMultiDataResultCount() |
806 | 864 | { |
807 | 865 | int c = SafeReadByte(); |
|
0 commit comments