无法使用RESP在Redis服务器上执行命令

时间:2018-05-04 13:42:13

标签: c# sockets redis

我正在尝试通过套接字将命令从.NET控制台应用程序发送到Redis实例。我不明白为什么发送的命令没有应用,因为发送了字节。我已尝试使用RESP协议和正常命令。但是没有应用于服务器:

Option Explicit

Public Const strSA As String = "C:\Users\tempo\Desktop\Managed Fund "
Public newWorkbooks As Collection

Sub iris()
    Dim i As Long
    Dim nm As String
    Set newWorkbooks = New Collection

    With ActiveSheet
    With .Range(.Cells(1, "A"), .Cells(.Rows.Count, "A").End(xlUp).Offset(0, 1))
        .Sort key1:=.Columns(1), order1:=xlAscending, _
              key2:=.Columns(2), order2:=xlAscending, _
              Header:=xlYes, MatchCase:=False, _
              Orientation:=xlTopToBottom, SortMethod:=xlStroke
    End With

    For i = 2 To .Cells(.Rows.Count, 1).End(xlUp).Row
        nm = .Cells(i, "A").Value2
        If LCase(nm) = LCase(.Cells(i - 1, "A").Value2) _
        And _
           LCase(nm) <> LCase(.Cells(i + 1, "A").Value2) _
        Then
            newWorkbooks.Add ("Managed Fund " + nm + ".xlsx")
            newiris nm, .Cells(i, "B").Value2
        End If
        Next
    End With

    CloseWorkbooks

End Sub

Sub newiris(nm As String, nfo As String)
    Application.DisplayAlerts = False
    With Workbooks.Add
        Do While .Worksheets.Count > 1: .Worksheets(2).Delete: Loop
        .Worksheets(1).Cells(1, "A").Resize(1, 2) = Array(nm, nfo)
        .SaveAs Filename:=strSA & nm, FileFormat:=xlOpenXMLWorkbook
    End With
End Sub

Sub CloseWorkbooks()
    Dim i As Integer
    Dim wb As Workbook

    For i = 1 To (newWorkbooks.Count)

        Set wb = Workbooks(newWorkbooks(i))
        wb.Close savechanges:=False

    Next i
    Application.DisplayAlerts = True
End Sub

执行命令之前套接字的状态

enter image description here

可以因为编码吗?

1 个答案:

答案 0 :(得分:0)

问题在于命令:

对于命令protocol我正在创建一个RESP查询:

set a 200

问题是我认为该值应该以整数形式发送。相反,我必须将其写为批量字符串:

*3\r\n$3\r\nset\r\n$1\r\na\r\n:200\r\n

而不是

$3\r\n200\r\n