Common commands for five data structures of the Redis database

Source: Internet
Author: User

1. String

Set sets the key value pair

Set name Xiaozhang

Get gets the key value corresponding to the key

Get name returns NIL when the key does not exist the client converts to None

Del deletes the value of the specified key

Del name returns 0 when the key does not exist

2. List (can be interpreted as an array in PHP)

Lpush inserts a new element from the beginning of the list, returning the length of the list after inserting the new element

Lpush List-key Item

Lpop Popup An element from the beginning of the list

Lpush List-key Returns the element that was popped, type string

Lrange gets the element value of the key within the specified range, 0-1 is the last element from the first element to the penultimate, and if 2 is the second element to the penultimate

Lrange List-key 0-1

Lindex gets the element at the specified position in the list

Lindex List-key 1

Note: The elements in the list can be repeated

3. Collection

Sadd add elements to the collection, elements can also be strings, floating-point

Sadd Set-key Item added successfully returns 1, otherwise 0, the added element is not added, will return 0

Sadd Set-key item2

Smembers displays all the elements in the collection, if the elements are very slow, so don't mess with

Smembers Set-key

Sismember finds whether the specified element exists in the collection, or returns 0 if there is a return of 1

Sismember Set-key Item

Srem removes the specified element from the collection

Srem Set-key Item

4. Hash (hash)

Hset setting key-value pairs

Hset Hash-key sub-key1 value1 set to return successfully 1

Hget gets the value corresponding to the setting key

Hget Hash-key Sub-key1

Hgetall gets all the key-value pairs in the hash

Hgetall Hash-key

Hdel Delete the value of the specified key

Hdel Hashh-key Sub-key1

5.zset ordered set

Zadd adds a member with a given score to an ordered set

Zadd Zset-key 723 Member1

Zrange gets multiple elements from a sequel river, depending on where the element is located in the ordered list

Zrange Zset-key 0-1 withscores if not with ' withscores ', gets the members of the collection

Zrangebyscore gets all elements of an ordered set within a given distribution range

Zrangebyscore Zset-key 0 880

Zrem if the given member exists in an ordered set, then the element is removed

Zrem Zset-key Member1

Common commands for five data structures of the Redis database

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.