Learning from the Redis database and interacting with Python

Source: Internet
Author: User
Tags delete key redis redis server

1. Introduction to the database:

  Currently, there are two main types of databases: relational database (RDBMS), non-relational database (NoSQL);

(1). Relational database RDBMS: It is a database based on the relational model, which uses mathematical concepts and methods such as set algebra to process the data in the database;

Key products for relational databases:

Oracle: Used in previous large-scale projects, banking, telecommunications and other projects

The most widely used relational database in the Mysql:web era

SQLite: Lightweight database, mainly used in mobile platform

       

(2). Non-relational database (NoSQL): Not only SQL, refers to the non-relational database, does not support SQL statements, storage structure and the traditional relational database of that kind of relational table is completely different,

The data stored in NoSQL is in kv form.

Non-relational database main products:

Mongodb

Redis

Hbase Hadoop

Cassandra Hadoop

2. Introduction to Redis:

  Redis is a member of the NoSQL technology Camp, an open source use of the ANSI C language, a support network, a memory-based, persistent log-type, Key-value database, and a multilingual API. Redis supports persistent storage of data, not only for simple key-value types of data, but also for storage of data structures such as List,set,zset,hash, which is extremely high performance and is used primarily as a cache.

3. Data manipulation

  String

Set Value: Set key value

Get value: Get key

Set Expiration time: Setex Bey seconds value

Set multiple key-value pairs: Mset key1 values1 key2 values

Append value: Append key value

Delete all key-value pairs: Flushall

Key command:

View all keys that match a given pattern: keys pattern

Determine if key exists: Exists key

Delete key and corresponding value: Del key1 key2

Set expiration time; Expire key seconds

Hashing (hash):

To set a single property: Hset key filed value

Set multiple properties: Hest key filed1 value1 filed2 value2

Gets the value of an attribute; Hget Key filed

Gets the value of multiple properties; Hget Key Filed1 Filed2

Gets all properties of the specified key: Hget key

Gets the value of all properties; Hval key

4. Redis's interaction with Python

  Installing Redis pip Inatall Redis

< Code class= "Lang-python" >from redis import *

   if __name_ _== "__main__": try: # Create a Strictredis object and build it with a Redis server? Connect Sr=strictredis (         Decode_responses=true           
    # 设置值
    sr.set("name", "laowang")
# 获取键name的值 result = sr.get(‘name‘) # 输出键的值,如果键不存在则返回None print(result) except Exception as e: print(e)

    

Learning from the Redis database and interacting with Python

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.