#!/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