Python Operations Redis--------------database additions and deletions

Source: Internet
Author: User
Tags redis

Installing a third-party module Redis

Import Redis

I. Connect to the database, and change the operation and additions.

1. Connecting data

(1). host Required Server IP
(2). Port number Default thing 6379, can not fill in, if changed to other port number, to fill in

(3). Password is not filled by default, if you set a password, to fill in

(4). DB Required value is an integer that represents the first few databases

2. Adding and deleting change operation string type

(Redis is a key-value pair)

2.1 Add/Modify Key-value value

You can set the expiration time as follows:

2.2 Querying data

(1). Gets the value of value by the key value of the Get method, gets the binary

Converts the acquired value to a string by using the Decode () method

The correct result:

(2). When key does not exist, get non-existent key, do not convert to string, value return value does not error, is none

Converted to a string to get the nonexistent key, the error is as follows:

2.3 Delete the specified key, when the deleted key does not exist, also does not error

2.4 Other methods

Python Operations Redis--------------database additions and deletions

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.