Redis data types

Source: Internet
Author: User

Redis supports 5 types of data, which are described below:

Strings-String

The Redis string is a sequence of bytes. In Redis, strings are binary safe, which means they have a known length that is not determined by any special character termination, so they can store anything for up to 512 megabytes in length.

Example
Redis 127.0.0.1:6379> SET name "Yiibai" Okredis 127.0.0.1:6379> GET name "Yiibai"

In the example above, using the Redis command set and the name of Get,redis is the Yiibai key stored in the Redis string value.

Note: The string value can store the maximum length of 512 megabytes.

Hashes-Hash value

A collection of Redis hash key value pairs. A Redis hash value is a mapping between a string field and a string value, so they are used to represent the object

Example
Redis 127.0.0.1:6379> hmset user:1 username yiibai password Yiibai points 200OKredis 127.0.0.1:6379> Hgetall user:11 ) "username" 2) "Yiibai" 3) "password" 4) "Yiibai" 5) "points" 6) "200"

In the example above, the hash data type is used to store the object that contains the user's basic information for the user. Here Hmset,hextall is the key for the Redis command user:1.

Each hash can be stores up to 232-1 field-value pairs (more than 4 billion).

Lists-List

The Redis list is a simple list of strings, sorted in order of insertion. You can add elements to the head or tail of the Redis list.

Example
Redis 127.0.0.1:6379> lpush tutoriallist redis (integer) 1redis 127.0.0.1:6379> lpush tutoriallist mongodb (integer ) 2redis 127.0.0.1:6379> lpush tutoriallist rabitmq (integer) 3redis 127.0.0.1:6379> lrange tutoriallist 0 101) "Rabi TMQ "2)" MongoDB "3)" Redis "

The maximum length of the list is 232-1 elements (4294967295, with more than 4 billion elements in each list).

Sets-Collection

A Redis collection is an unordered collection of strings. In Redis, you can add, delete, and test a file for a member that has time complexity in O (1).

Example
Redis 127.0.0.1:6379> sadd tutoriallist redis (integer) 1redis 127.0.0.1:6379> sadd tutoriallist mongodb (integer) 1redis 127.0.0.1:6379> sadd tutoriallist rabitmq (integer) 1redis 127.0.0.1:6379> sadd tutoriallist rabitmq ( Integer) 0redis 127.0.0.1:6379> smembers tutoriallist1) "RABITMQ" 2) "MongoDB" 3) "Redis"

Note: In the example above, RABITMQ sets the property by two times, but only once because the uniqueness is added.

The maximum number of members in the set is 232-1 (4294967295, the collection member is more than 4 billion).

Collection sort

The collection of Redis is sorted like a Redis collection, a collection of strings that are not duplicated. The difference is that each member of an ordered set is associated with fractions, which are used in order to take an ordered set command, from the smallest to the largest fraction. Although the members are unique, the scores may be duplicated.

Example
Redis 127.0.0.1:6379> zadd tutoriallist 0 redis (integer) 1redis 127.0.0.1:6379> zadd tutoriallist 0 mongodb (integer ) 1redis 127.0.0.1:6379> zadd tutoriallist 0 rabitmq (integer) 1redis 127.0.0.1:6379> zadd tutoriallist 0 rabitmq (int Eger) 0redis 127.0.0.1:6379> zrangebyscore tutoriallist 0 10001) "Redis" 2) "MongoDB" 3) "RABITMQ"


Reprint Please specify: Article reprinted from: Easy Hundred tutorials [http:/www.yiibai.com]
This article title: Redis data types
This address: http://www.yiibai.com/redis/redis_data_types.html

Redis data types

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.