Skip to content
loading...

Low-level Redis Python client (Ping Pong Example)

github logo ・1 min read  

Here is a basic low-level ping-pong Redis Python client in case anyone is looking for it. Redis uses the RESP protocol for its client/server communication, read more on the official docs.


import socket


# Initialize a socket object
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 

# Redis server is hosted on port 6379
address = ("127.0.0.1", 6379)
client.connect(address)

# Note, clients use RESP arrays to send Redis commands
client.sendall(b"*1\r\n$4\r\nPING\r\n")

# Receive a maximum of 24 bytes from server
response = client.recv(24)
response = response.decode("ASCII")
response = response[1:]
print(response)

client.close()

Photo by Máximo from Pexels

twitter logo DISCUSS
Classic DEV Post from Nov 23 '19

Who are your favorite writers here on DEV?

Who are some people whose posts on DEV you particularly enjoy?

Nic profile image
I love life, burger, beer & adventure. I know C, Rust, Arduino, HTML, Jquery, Python and more.
Join DEV

Learn how to be better at computers and programming and stuff. DEV 4 life.