Python Simple Operation Redis

Source: Internet
Author: User
Tags install redis

1. Installing Redis

Command: sudo pip install Redis

2. Connect to Redis

Import= Redis. Redis ("192.168.86.127", port=6379, db=10)

3. Add 10 data to the list in Indexs

 for  in range:    redis_client.rpush ("indexs", i)

4. View the length of the Indexs key

Llen = Redis_client.llen ("indexs")print'llen:  ', Llen

5. Remove a piece of data from a Redis key

Job = Redis_client.lpop ("indexs")print'job:  ', Job

6. Get all the data in the Indexs key

Jobs = Redis_client.lrange ('indexs', 0,-1)

7.redis Setting value

Redis_client.hmset ("hot_keys", {"singers":"  Hot_singer"}) redis_client.hmset ("hot_keys", {"  songs":"hot_song"})

8.redis Get Value

arraykey=["singers","songs"]for in  Arraykey:    for in  redis_client.hmget ("Hot_keys  ", key):        Print key,line

9.redis get all keys under a certain DB

print Redis_client.keys ()

10.redis Delete a key

Redis_client.delete ('indexs')

Python Simple Operation Redis

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.