Python Operation Redis

Source: Internet
Author: User

operating Redis Redis is a nosql type of database with data in memory, fast read and write speeds, Python operation Redis using Redis module, PIP installation

Import redis     r = redis. Redis (host= 127.0.0.1 ' ,port= 6379,db=0 #指定连接redis的端口和ip以及哪个数据库 R. Set(' name ', ' value ')#set A value of type string R. Setnx(' name2 ', ' value ')#设置的name的值, set if name does not exist     r. Setex ( ' Name3 ' ,   ' value ' ,  3) #设置的name的值, and time-out time, key will automatically expire R. Mset(k1=' v1 ',k2=' v2 ')#批量设置值 R. Get(' name ')#获取值 Print(r. Mget(' K1 ',' K2 '))#批量获取key      R. Delete(' name ')#删除值 R. Delete(' K1 ',' K2 ')#批量删除 #====== The following is the operation hash type R. Hset(' hname ', ' key ', ' value ')#set The value of the hash type R. Hset(' hname ', ' Key1 ', ' value2 ')#set The value of the hash type R. Hsetnx(' hname ',' Key2 ',' Value23 ')#给name为hname设置key和value, Unlike the one above, when key doesn't exist. #才会set R. Hmset(' hname ',{' k1 ':' v1 ', 'K2 ':' v2 '})# Bulk set Hash type key and value R. Hget(' name ', ' key ')#获取哈希类型的值 Print(r. Hgetall(' hname '))#获取这个name里所有的key和value R. Hdel(' hname ',' key ')#删除哈希类型的name里面指定的值 Print(r. Keys())#获取所有的key

Python 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.