Install redis-py and connect to Redis server settings and get Redis binary data

Source: Internet
Author: User
Tags download redis install redis redis server

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.