Python Redis operations

Source: Internet
Author: User
Tags string format

ImportREDISR=Redis. Redis (Host='1xx.x24.3xx.x0',#IP,password='hk139bc&*',#Passwordport=6379,#Port numberDb=1#The first few databases)#string format Operation#Change and deleteR.set ('Wahaha',"{A: ' 1 ', B: ' 2 '}") R.delete ('Wahaha') R.setex ('a','111', 50)#set the data for the expiration period of 50 seconds
Print (R.get (' a ')) #b ' 111 '
Print (R.get (' a '). Decode ()) #111
#带文件夹操作
R.setex (' A:aa ', ' 111 ', 50)
R.setex (' a:vaa ', ' 111 ', 50)
Print (R.get (' A:aa ')) #b ' 111 '

# Get all keys Print (R.keys ()) # get to all keys [B ' A ', B ' myself ', B ' stu_info_nhy ', b ' ytt ', B ' Bab ', B ' ab '] Print (R.keys ('a*')) # get to all the A starts with key [B ' A ', B ' ab ']
#hash type of dataR.hset ('Aaa:aa','a','{1: "Good Drink", 2: "B"}')Print(R.type ('Aaa:aa'))#B ' Hash 'Print(R.hget ('Aaa:aa','a'). Decode ())#{1: "Good Drink", 2: "B"}Print(R.hgetall ('Aaa:aa'))#{b ' a ': B ' {1: ' \xe5\xa5\xbd\xe5\x96\x9d ', 2: ' B '} '}R.expire ('Aaa:aa', 50)#Set Expiration TimePrint(R.ttl ('Aaa:aa'))#returns the time at which the current distance expires

R.hdel (' Stu_info ', ' Gyx ')  #删除指定keyr. Delete (' Stu_info ')  #删除整个key

Python Redis operations

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.