Python Operation Redis--string

Source: Internet
Author: User

#!/usr/bin/python#!coding:utf-8"""complete operation of string type data with Redis module"""ImportRedisif __name__=="__main__":    Try: Conn=redis. Redis (host='192.168.80.128', port=6379,db=0)#The Redis module does not support using Select to change the current database.         Print(Conn.ping ())#test the client connection to the server side is normal. If "True" is returned normally. Conn.set ('name','Shang Brother')            #for name This key is associated with a value of "Shang elder brother".         Print(Conn.get ('name'). Decode ('Utf-8'))            #Remove the value associated with name this key and print.             #Redis Support Mget,mset        Print(Conn.keys ('*'))            #gets all the keys in the current database.             #1. * Number matches all characters.             #2. Number matches one character.             #3, [] include any character between parentheses.             #4, \ Matches character x and is used to escape symbols.         Print(Conn.exists ('name'))            #determines whether a key exists.         Print(Conn.type ('name'))            #determines the type of a key. result=conn.delete ('name')        Print(Result)#Deletes a key, returns 1 if the deletion succeeds, or returns 0. Conn.set (' Age', 16) Result=CONN.INCR (' Age', 2)        Print(Conn.get (' Age'))            #increment the value associated with a key, which is atomic, which means it is safe for multiple clients.             #the self-increment value can be obtained directly through the INCR function, which means that the GET function is not adjusted.             #Although the string type can save the value directly, this data can also be self-increasing, but it is better to think of it as a string, thinking that others can do append.         Print(CONN.DECR (' Age', 2)) Conn.append (' Age','BBBB')        Print(Conn.get (' Age'))            #executes the Append method.         Print(Conn.strlen (' Age'))            #returns the length of the character.             exceptException as err:Print(ERR)

Python Operation Redis--string

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.