mirror of
https://github.com/EchoVault/SugarDB.git
synced 2025-10-21 06:59:24 +08:00
Added PUBSUB commands and made pubsub module more compatible with redis-cli client
This commit is contained in:
@@ -219,6 +219,10 @@ func (server *Server) handleConnection(ctx context.Context, conn net.Conn) {
|
||||
|
||||
res, err := server.handleCommand(ctx, message, &conn, false)
|
||||
|
||||
if err != nil && errors.Is(err, io.EOF) {
|
||||
break
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if _, err = w.Write([]byte(fmt.Sprintf("-Error %s\r\n", err.Error()))); err != nil {
|
||||
log.Println(err)
|
||||
@@ -234,10 +238,7 @@ func (server *Server) handleConnection(ctx context.Context, conn net.Conn) {
|
||||
}
|
||||
|
||||
if len(res) <= chunkSize {
|
||||
_, err = w.Write(res)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
_, _ = w.Write(res)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -246,7 +247,10 @@ func (server *Server) handleConnection(ctx context.Context, conn net.Conn) {
|
||||
for {
|
||||
// If the current start index is less than chunkSize from length, return the remaining bytes.
|
||||
if len(res)-1-startIndex < chunkSize {
|
||||
_, _ = w.Write(res[startIndex:])
|
||||
_, err = w.Write(res[startIndex:])
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
break
|
||||
}
|
||||
n, _ := w.Write(res[startIndex : startIndex+chunkSize])
|
||||
|
Reference in New Issue
Block a user