Redis database (set type and zset type)

Source: Internet
Author: User
Tags redis cluster
Set is a collection, which is a disordered set of the string type. set is implemented through hashtable. the time complexity of adding, deleting, and searching is O (1). For the set, we can

Set is a collection, which is a disordered set of the string type. set is implemented through hash table. the time complexity of adding, deleting, and searching is O (1). For the set, we can

1. set Type

Set is a collection of unordered string types. set is implemented through hash table. the time complexity of adding, deleting, and searching is O (1 ), for a set, we can take the Union, intersection, and difference set. Through these operations, we can implement the friend recommendation and Blog tag FUNCTIONS In SNS.

Set common operations:

(1) sadd

Add an element to a collection. Example: sadd set1 Hello

(2) smembers

View all elements in the set. Example: smembers set1

(3) srem

Deletes a specified Element in the set. Example: srem set1 Hello

(4) spop

A set element named "Sino" is randomly displayed. Example: spop set1

(5) sdiff

Evaluate the difference set of the two sets. For example, sdiff set1 set2 indicates that all the elements in set1 and set2 are retained.

(6) sdiffstore

Saves the returned difference set into a set. For example, sdiffstore set3 set1 set2 indicates saving the difference set of set1 and set2

Set set3.

(7) sinter

Returns the intersection of the given two sets. For example, sinter set1 set2 indicates that the intersection of set1 and set2 is returned.

(8) sinterstore

Store the intersection of two sets into one set. For example, sinterstore set3 set1 set2 indicates the intersection of set1 and set2.

Save it to set3.

(9) sunion

Returns the union of the given two sets. For example, sunion set1 set2 indicates that the Union of set1 and set2 is returned.

(10) sunionstore

Saves the union of the two sets into a set. For example, the sunionstore set3 set1 set2 indicates the Union of set1 and set2.

Save to set set3

(11) smove

Remove member from the set corresponding to the first key and add it to the second set.

For example, smove set1 set2 Hello indicates to move the Hello element in set1 to set2.

(12) scard

Returns the number of elements in the set corresponding to the key. For example, scard set1.

(13) sismember

Determines whether an element is a set element. For example, sismember set1 Hello indicates to judge whether Hello is set to set1.

.

(14) srandmember

Returns an element of a set named key at random. Example: srandmember set1.

Ii. zset type

Zset adds an order based on the set to form an ordered set.

Common zset operations:

(1) zadd

Add an element to the zset of Ordered Sets. Example: zadd zset 1 Hello

(2) zrange

Output all the elements in the specified range in zset, in the ascending order of score.

For example, zrange zset 0-1 withscores indicates that all elements in zset are output in an ordered set and the sequence number is output.

(3) zrem

Delete the element member in the zset set whose name is key. For example, zrem set1 Hello.

(4) zincrby

Adds the serial number of the specified Element in the zset of the ordered set to the specified value. Example: zincrby zset 4 Hello

(5) zrank

Returns the ranking of elements in the zset set with the key name, ranking from small to large by subscript. For example, zrank zset Hello.

(6) zrevrank

Returns the ranking of elements in the zset set with the key name, which is ranked from large to small according to the following table. For example, zrevrank zset Hello.

(7) zrevrange

Outputs all elements in the Set in ascending order of score. For example, zrevrange zset 0-1 withscores.

(8) zrangebyscore

Returns the element of the given range in the set. Example: zrangebyscore zset 2 3 withscores

(9) zcount

Returns the number of scores in a given range in a set. Zcount zset 2 3

(10) zcard

Returns the number of elements in a collection.

(11) zremrangebyrank

Deletes the elements of a given interval according to the index. Example: zremrangebyrank zset 1 2

(12) zremrangebyscore

Deletes the element of a score in the specified range. Example: zremrangebyscore zset 1 2

Install and test Redis in Ubuntu 14.04

Redis cluster details

Install Redis in Ubuntu 12.10 (graphic explanation) + Jedis to connect to Redis

Redis series-installation, deployment, and maintenance

Install Redis in CentOS 6.3

Learning notes on Redis installation and deployment

Redis. conf

Redis details: click here
Redis: click here

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.