Skip to content

qunchenmy/redis_protocol

 
 

Repository files navigation

Redis Protocol

https://badge.fury.io/py/redis_protocol.png https://travis-ci.org/youngking/redis_protocol.png?branch=master https://pypip.in/d/redis_protocol/badge.png

Redis Protocol implemented by python

Usage

This is the protocol implemented followed by redis protocol specification. I had used it in my redis_proxy project.

>>> from redis_protocol import decode, encode
>>> encode("ping")  # encode a request
... '*1\r\n$4\r\nping\r\n'
>>> decode('*1\r\n$4\r\nping\r\n') # decode a request body
... ["ping"]
>>> decode("$6\r\nfoobar\r\n")  # decode a response
... "foobar"

Parse redis protocol stream

Parse redis protocol stream to redis commands,such as redis pipeline requests or raw responses.

redis protocol stream is the RESP serialization format data.

redis RESP : http://redis.io/topics/protocol

example :

data = '*3\r\n$3\r\nSET\r\n$15\r\nmemtier-8232902\r\n$2\r\nxx\r\n
        *3\r\n$3\r\nSET\r\n$15\r\nmemtier-8232902\r\n$2\r\nxx\r\n
        *3\r\n$3\r\nSET\r\n$15\r\nmemtier-7630684\r\n$3\r\nAAA\r\n'
print parse_stream(data)

output :

['SET memtier-8232902 xx', 'SET memtier-8232902 xx', 'SET memtier-7630684 AAA']

About

Redis Protocol implemented by python

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 48.4%
  • Makefile 28.5%
  • Shell 23.1%