我当前正在本地计算机上运行Redis,并且正在使用GCDAsyncSocket库连接到它。连接工作正常,我能够执行redis命令,但无法收到来自redis的响应 这是我的代码
func startSocket()
{
socket = GCDAsyncSocket.init(delegate: self, delegateQueue: DispatchQueue.main)
do
{
try socket.connect(toHost: "127.0.0.1", onPort: 6379, withTimeout: 10)
print(1)
}
catch
{
print("error")
}
}
func socket(_ sock: GCDAsyncSocket, didConnectToHost host: String, port: UInt16) {
print("2")
connect()
print(host)
}
func socket (_ sock: GCDAsyncSocket, didRead data: Data, withTag tag: Int) {
print("yes")
if (tag == 1)
{
let x = data
let Recieved: String = String(data: x, encoding: String.Encoding(rawValue: String.Encoding.utf8.rawValue))!
print(Recieved)
}
}
func connect()
{
let name = "SET ONE TEST \r\n"
print(name)
let sent = name.data(using: String.Encoding.utf8)
socket.write(sent!, withTimeout: 10, tag: 1)
}
当我在redis实例中选中GET ONE时,我按预期方式进行了TEST,但无法在函数“ func socket(_ sock:GCDAsyncSocket,didRead data:Data,withTag tag:Int)”中获取接收到的变量。