Added PUBSUB commands and made pubsub module more compatible with redis-cli client

This commit is contained in:
Kelvin Clement Mwinuka
2024-02-28 10:14:46 +08:00
parent 6566bb41c4
commit e18257e600
5 changed files with 241 additions and 47 deletions

View File

@@ -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])