This document provides a brief introduction to using the Python version of Redis client redis-py to connect Redis and perform setup and acquisition of Redis binary data.
Description
Commands such as set,get,setnx,append can also be used to set binary data.
Because Redis's own client redis-cli is not easy to set up binary data, we use Python's client here to
There are three ways of installing redis-py:
1. Pip Install Redis
2. Easy_install Redis
3. Installing from Source: Python setup.py Install
Below we only introduce from the source installation redis-py.
Download Redis-py:
wget Https://github.com/andymccurdy/redis-py/archive/master.zip
Unzip:
Unzip Master
cdredis-py-master/
Installation:
Python Setup.pyinstall
Setting up and acquiring Redis binary data
[[email protected] redis-py-master]# python
Python 3.4.4 (default, Mar 13 2016, 15:17:12)
[GCC 4.4.420100726 (Red Hat 4.4.4-13)] on Linux
Type "Help", "copyright", "credits" or "license" for more information.
>>> Import Redis
>>> R =redis. Strictredis (host= ' localhost ', port=6379, db=0)
>>>r.set (' mybits ', 0b10010010000)
True
>>> Bin (int (r.get (' mybits ')))
' 0b10010010000 '
>>> r.append (' mybits ', 0b1001)
5
>>> Bin (int (r.get (' mybits ')))
' 0b10110110101001 '
>>> r.get (' mybits ')
B ' 11689
We view the value of the Mybits key through REDIS-CLI:
[Email protected] ~]# redis-cli-h localhost-p 6379
localhost:6379> get ' mybits '
"11689"
You can see that the obtained binary (10110110101001) is converted to a decimal (11689) value.
Install redis-py and connect to Redis server settings and get Redis binary data