Redis from getting started to forgetting

Source: Internet
Author: User

Key operation

Keys *

*: Wildcard with any number of characters

?: Pass a single character

[]: 1 characters in parentheses

Exists key exists return 1, no return 0

Type key

Rename Oldkey Newkey

Common data types:

The most commonly used data types for Redis are the following:

    • String
    • Hash
    • List
    • Set
    • Sorted Set
String:

Set key value

Get key

Append key Value # Appends a string, returning the new string length

substr key start end # intercepts a string and does not modify the value of key

List:

Lpush Key Value # header added

Rpush key Value # trailing add

Llen Key # View list length

Lrange start End # View a list Lrange key 0-1 returns all data

Lpop Key # Removes elements from the left

Rpop Key # remove element from right

LSet Key index Value # Specifies subscript element

Set:

Sadd Key Member # add element

Srem Key Member # delete element

Spop Key # Delete and return elements

Sismember Key member # to determine if member is in set, return 1 means there

Sinter key1 Key2 Key3 # Returns the intersection of a given set

Sunion key1 Key2 Key3 # Returns the set of a given set

Sdiff key1 Key2 Key3 # Returns the difference set for a given set

Smembers Key # Returns all elements of the collection

Sorted set:

Zadd Key Score member # add element

Zrem Key Member # delete element

Zrange Key Start end # Returns ordered result, ascending

Zcard Key # Returns the number of elements in the collection

Zscore key Element # returns the score corresponding to the given element

Hash:

Hset key field Value # Set hash value

Hget key Field # get hash value

hexists key Field # TEST Specifies whether the field exists

Hdel key Field # Deletes the specified hash field

Hlen Key # Gets the number of domains

Hkeys Key # Get all the domain names

Hgetall # Get all domain names and values

Key design:

Users table user, convert to key-value storage:

UserID Username Password Email

9 Lisi 1111111 [email protected]

Set User:userid:9:username Lisi

Set User:userid:9:password 111111

Set user:userid:9:email [email protected]

Redis from getting started to forgetting

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.