Python Operation Redis

Source: Internet
Author: User
Tags delete key redis server

Some of their own initial attempts, there is no place to be wrong, thank you ~

Download the Redis library used by Python:
HTTPS://pypi.python.org/packages/source/r/redis/redis-2.10.3.tar.gz
Install after decompression:
Python setup.py Install
Operation Code:
#-*-coding:cp936-*-ImportRedis#Initializing the connection configuration#here is an explanation of the following db parameter:#db Incoming shaping value, the range is limited to the server configuration. #The default Redis server is configured as DATABASES=16, which is the value between DB 0~15. #data between different db is independent of each other, so in multi-user cases, DB can be specified to avoid conflicts caused by data rewriting. Redis_client = Redis. Redis (host=' 127.0.0.1', port=6379, Db=0, password='redis123$', socket_timeout=3)#operating Redis#It should be noted that the Python-redis should be in the form of short connections, ShikaTry:    #Verify that you are logged on correctly    Printredis_client.ping ()#gets the number of the current key    Printredis_client.dbsize ()#Get all keys    PrintRedis_client.keys ()#set the key valueRedis_client.set ('Host','@localhost')    #See if the key exists    PrintRedis_client.exists ('Host')    #View Key data Types    PrintRedis_client.type ('Host')    #Reading key Values    PrintRedis_client.get ('Host')    #change the name of the keyRedis_client.rename ('Host','Foo')    #Read key value 2    Printredis_client['Foo']    #Delete keyRedis_client.delete ('Foo')    #Remove all key valuesredis_client.flushdb ()#Save ChangesRedis_client.save ()#connection error, usually caused by an incorrect address or port numberexceptRedis. Connectionerror, E:Print 'Connectionerror:%s'%E.message#response error, incorrect database name or password, or other error causedexceptRedis. Responseerror, E:Print 'Responseerror:%s'% E.message
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.