Redis Ruby Client Learning (iii)

Source: Internet
Author: User

Pick up a Redis Ruby client learning (ii)

For the five data types of Redis: string, hash (Map), list, collection (sets) , and ordered collection (sorted sets), the previous article describes the hashes and lists.

One, assemble

    • Mset Add one or more elements to the collection (set)
" Redis "  ='my_set'value1'
    • SCard. Returns the cardinality of the key stored by the collection (the number of collection elements).
' My_set '

Returns an element that sets the difference between a collection and a given set.

' My_set ' ' My_set2 '
    • Sinter Returns the intersection of the members that specify all the collections.
' My_set ' ' My_set2 '
    • Sismember. Returns whether a member member is a member of a stored collection key .
' My_set ' ' value2 '
    • Smembers. Returns key all the elements of the collection.
' My_set '
    • Smove.

membermoves from the source collection to the destination collection. For other clients, the element at a particular time will appear as a source member of or a destination collection.

If the source collection does not exist or does not contain the specified element, this smove command does nothing and returns 0 . Otherwise, the object will be removed from the source collection and added to the destination collection. If the element is already present in the destination collection, the Smove command removes only the element from the source collection.

If source  and destination not a collection type, an error is returned.

' My_set2 ' ' My_set ',  'temp'
    • Srem.

keyremoves the specified element from the collection. If the specified element is not an key element in the collection, ignore if the key collection does not exist and is treated as an empty collection, the command returns 0 .

If key the type is not a collection, an error is returned.

' My_set ' ' Temp '
    • Sunion.

Returns all the members of a given collection of multiple sets.

' My_set ' ' My_set2 '

Two, an orderly set

    • Zadd.

The command adds the specified member to the ordered set of keys corresponding to each member with a fraction. You can specify multiple score/member combinations. If a specified member is already in the corresponding ordered set, the score is updated to the latest, and the member is re-adjusted to the correct position to ensure that the collection is orderly. If key does not exist, an ordered collection of these members is created, as if it were added to an empty collection. If key exists, but it is not an ordered set, an error is returned.

The value of a fraction must be a string that represents a number, and can be a floating point of type double.

' Z_set ', 3,'three'
    • Zcard. Returns the number of ordered set elements for key.
' Z_set '
    • Zount. Returns the ordered set key, where the score value is between Min and Max (the default includes a member of the score value equal to Min or max).
' Z_set ', 1,3
    • Zincrby.

Adds an increment increment to the score value of the member member of the ordered set key. If member is not present in key, adding a member,score in key is increment (as if the score before it is 0.0). If key does not exist, it creates an ordered collection that contains only the specified member members.

When key is not an ordered set type, an error is returned.

The score value must be a string representation of an integer value or a double-precision floating-point number, and can accept a double-precision floating-point number. It is also possible to give a negative number to reduce the value of score.

' Z_set ', ten,'both'

    • Zrange.

Returns the member of the ordered set key, within the specified interval. The members are sorted by increasing the score value (from small to large). Members with the same score value are sorted by dictionary order.

Use the Zrevrange command if you want members to be score by decreasing the value of the score (decreasing by dictionary order when the equality is equal). The subscript parameter start and stop are based on 0, that is, 0 indicates the first member of an ordered set, 1 indicates the second member of an ordered set, and so on. You can also use a negative subscript, which means 1 for the last member, 2 for the penultimate member, and so on.

An out-of-range subscript does not cause an error. If the value of start is larger than the maximum subscript for an ordered set, or Start > Stop, the Zrange command simply returns an empty list. On the other hand, if the value of the stop parameter is larger than the maximum subscript for an ordered set, Redis treats stop as the maximum subscript.

' Z_set ', 1,-1
    • Zrank.

Returns the rank of the member member in the ordered set key. Where ordered set members are arranged in ascending order of score values (from small to large). The ranking is based on 0, meaning that the member with the lowest score value is ranked at 0.

' Z_set ','both'
    • Zrem. Removes a member from the sorted collection
' Z_set ','both'
    • Zrank. Returns the score value of the member member in the ordered set key.
' Z_set ','five'

Summary:

This article mainly introduces the common methods of collection and ordered set in five data types of Redis Ruby client.

Redis Ruby Client Learning (iii)

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.