Simple introduction of five types of redis commonly used in the data

Source: Internet
Author: User
1.string

The string in Redis is a sequence of bytes. The strings in Redis are binary safe, meaning that their lengths are not determined by any particular terminating character. As a result, you can store anything up to 512 megabytes in a string.

There is a set get Operation command that is case-insensitive

2.hash

a Redis hash/hash (hashes) is a collection of key-value pairs. it provides a mapping of field and field values. Field values can only be string types, and other types such as hash type, collection type, and so on are not supported.

assignment Syntax: Hset key field value
Set a field value,
The Hset command does not differentiate between insert and update operations, and when an insert operation is performed, the Hset command returns 1, which returns 0 when the update operation is performed.
Value syntax: Hget key field
Set multiple field syntax: Hmset key field value [field value ...]
Take multiple value syntax: Hmget key field [field ...]
Get all field value syntax: Hgetall key
Delete field syntax: Hdel key field [field ...]
Ex:hmset items1 ID 3 name Apple price 99
3.listRedis list is used to store the linked list, two-way linked lists to store data, features: Quick additions and deletions, slow query (LinkedList)
add element to the left of the list: Lpush key value [value ...]
Eject element from left of list: Lpop key
Add elements to the right of the list: Rpush key value [value ...]
Eject element from right of list: Rpop key
To get the number of elements in a list: Llen key
View list syntax: Lrange key start stop
All of the elements between start and stop (containing elements at both ends) are returned, and the index starts at 0 and can be negative, such as: "-1" represents the last element.

4.set and ZsetSet collection type: unordered, not repeatable
add element syntax: Sadd key member [member ...]
Delete element syntax: Srem key member [member ...]
Get all the elements in the collection: Smembers key
To determine whether an element is in the collection: Sismember Key member
SortedSet, also called Zset, is an ordered set, sortable, but unique. The difference between SortedSet and set is to add a fraction to the elements in the set and then sort by that fraction.
add element: Zadd key score member [score ...]
Adds an element and a fraction of the element to an ordered set, and replaces the original score with the new fraction if the element already exists.
Get a list of elements in a range Zrange key start stop [withscores] returns in order of element fractions from small to large
Return in order of element fractions from large to small
Syntax: Zrevrange key start stop [Withscores]
Get score of element: Zscore Key Member
Delete element Zrem key member [...]
The score of the element can be obtained by adding the Withscores parameter at the end of the command
Application: Sale of Goods
Product number 1001 Sales is 9, the product number 1002 sales are 10
Zadd Sellsort 9 1001 10 1002
Product number 1001 Sales plus 1:zincrby sellsort 1 1001
Product Sales ranking top 3 in the queue:
Zrevrange Sellsort 0 2 withscores

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.