Set operation of Python-redis

Source: Internet
Author: User

Collection as a non-repeating list

Unordered collection

Sadd (name,values): Add an element to the collection that corresponds to name

Smembers (name): Gets all members of the collection that the name corresponds to

127.0.0.1:6379> Sadd name John Jack Jack Andy (integer) 3127.0.0.1:6379> smembers name1) "Andy" 2) "John" 3) "Jack"

SCard (name): Gets the number of elements in the collection that the name corresponds to

127.0.0.1:6379> smembers name1) "Andy" 2) "John" 3) "Jack" 127.0.0.1:6379> scard name (integer) 3

Sdiff (keys, *args): The collection of elements in the first name corresponding collection and not in the other name corresponding collection

127.0.0.1:6379> smembers name1) "Andy" 2) "John" 3) "CSS" 4) "Jack" 5) "PHP" 127.0.0.1:6379> smembers web1) "PHP" 2) "JAV Ascript "3") "CSS" 4) "HTML" 127.0.0.1:6379> Sdiff name Web1) "Andy" 2) "John" 3) "Jack"

Sdiffstore (dest, Keys, *args): Gets the collection that corresponds to the first name and is not in the other name, and then adds it to the corresponding collection of dest

127.0.0.1:6379> smembers name1) "Andy" 2) "John" 3) "CSS" 4) "Jack" 5) "PHP" 127.0.0.1:6379> smembers web1) "PHP" 2) "JAV Ascript "3)" CSS "4)" HTML "127.0.0.1:6379> sdiffstore name_web name Web (integer) 3127.0.0.1:6379> smembers name_ WEB1) "Andy" 2) "John" 3) "Jack"

Sismember (name, value): Checks if value is a member of the collection that corresponds to name

127.0.0.1:6379> smembers web1) "PHP" 2) "JavaScript" 3) "CSS" 4) "HTML" 127.0.0.1:6379> sismember Web asp (integer) 0127.0.0.1:6379> sismember Web php (integer) 1

Smove (SRC, DST, value): Moves a member from one collection to another, SRC is a collection of moved members, moving members to the DST collection

127.0.0.1:6379> smembers name1) "Andy" 2) "John" 3) "Jack" 127.0.0.1:6379> smembers web1) "PHP" 2) "JavaScript" 3) "CSS "4)" HTML "127.0.0.1:6379> smove Web name php (integer) 1127.0.0.1:6379> smembers name1)" PHP "2)" Andy "3)" John "4)" Ja CK "127.0.0.1:6379> smembers Web1)" JavaScript "2)" CSS "3" HTML "

Spop (name): Returns and removes a member from the Right (trailer) of the collection

127.0.0.1:6379> smembers name1) "PHP" 2) "Andy" 3) "John" 4) "Jack" 127.0.0.1:6379> Spop name "Jack" 127.0.0.1:6379 > smembers name1) "PHP" 2) "Andy" 3) "John"

Srandmember (name, numbers): Numbers elements are randomly obtained from the collection corresponding to name

127.0.0.1:6379> smembers web1) "PHP" 2) "HTML" 3) "CSS" 4) "aspx" 5) "ASP" 6) "Ajax" 7) "JavaScript" 127.0.0.1:6379> Srandmember Web) "Ajax" 2) "JavaScript" (127.0.0.1:6379> srandmember Web) "HTML" 2) "CSS" 3) "aspx" 4) "JavaScript" 5) " Ajax

Srem (name, values): Removes certain values from the collection that corresponds to name

127.0.0.1:6379> smembers web1) "PHP" 2) "HTML" 3) "CSS" 4) "aspx" 5) "ASP" 6) "Ajax" 7) "JavaScript" 127.0.0.1:6379> Srem Web aspx (integer) 1127.0.0.1:6379> smembers web1) "PHP" 2) "HTML" 3) "CSS" 4) "ASP" 5) "Ajax" 6) "JavaScript"

Sinter (keys, *args): Gets the set of the name corresponding collection

Sinterstore (dest, Keys, *args): Gets the set of the name corresponding to the collection, and the result is saved to the corresponding collection of dest

127.0.0.1:6379> smembers name1) "Jack" 2) "Andy" 3) "PHP" 4) "John" 5) "Jane" 6) "HTML" 7) "CSS" 127.0.0.1:6379> smembers WEB1) "PHP" 2) "HTML" 3) "CSS" 4) "ASP" 5) "Ajax" 6) "JavaScript" 127.0.0.1:6379> sinter web name1) "PHP" 2) "HTML" 3) "CSS" 127 .0.0.1:6379> sinterstore web_name Web name (integer) 3127.0.0.1:6379> smembers web_name1) "PHP" 2) "CSS" 3) "HTML"

Sunion (keys, *args): Gets the associated set of the name corresponding to the collection

Sunionstore (Dest,keys, *args): Gets the associated set of the name corresponding to the collection and saves the result to the corresponding collection of dest

127.0.0.1:6379> smembers name1) "Andy" 2) "PHP" 3) "John" 4) "Jane" 5) "HTML" 6) "CSS" 7) "Jack" 127.0.0.1:6379> smembers WEB1) "PHP" 2) "HTML" 3) "CSS" 4) "ASP" 5) "Ajax" 6) "JavaScript" 127.0.0.1:6379> sunion name Web 1) "John" 2) "Jane" 3) "CSS "4)" HTML "5)" Jack "6)" ASP "7)" Andy "8)" JavaScript "9)" Ajax "" PHP "127.0.0.1:6379> sunionstore name_web name we B (integer) 10127.0.0.1:6379> smembers name_web 1) "John" 2) "Jane" 3) "CSS" 4) "HTML" 5) "Jack" 6) "ASP" 7) "Andy" 8) " JavaScript "9)" Ajax "PHP"

Sscan (name, cursor=0, Match=none, Count=none): matches the value in the collection corresponding to name

Sscan_iter (name, Match=none, Count=none): matches the value in the collection of name corresponding to the iteration

127.0.0.1:6379> smembers name_web 1) "John" 2) "Jane" 3) "CSS" 4) "HTML" 5) "Jack" 6) "ASP" 7) "Andy" 8) "JavaScript" 9 "Ajax") "PHP" 127.0.0.1:6379> sscan name_web 0  match j*1) "7" 2) 1) "JavaScript"   2) "John"   3) "Jane" 
   
    4) "Jack"
   
Ordered collection

Each element in an ordered set has a value and a fraction, which is specifically used to sort

Zadd (name, *args, **kwargs): Adds an element to the ordered collection of name

Zrange (name, start, end, Desc=false, Withscores=false, score_cast_func=float): Gets the element of the ordered collection of name corresponding to the index range, Start is an ordered set index start position (non-fractional), end is an ordered collection index ending position (non-fractional), Desc is a collation, by default, the order is sorted from small to large, withscores to get the element's score, and the default is to get the value of the element, Score_cast_ Func is a function of data conversion to fractions
Zrevrange (name, start, end, Withscores=false, score_cast_func=float): Sort from large to small

127.0.0.1:6379> zadd Web 3 HTML 7 CSS JavaScript 4 php (integer) 4127.0.0.1:6379> zrange web 0-1 withscores1) "HT ML "2)" 3 "3)" PHP "4)" 4 "5)" CSS "6)" 7 "7)" JavaScript "8)" 127.0.0.1:6379> Zrevrange Web 0-1 withscores1) "JavaScript" 2) "3" "CSS" 4) "7" 5) "PHP" 6) "4" 7) "HTML" 8) "3"

Zrangebyscore (name, Min, Max, Start=none, Num=none, Withscores=false, score_cast_func=float): Gets the element of the ordered set of name corresponding to the range of fractions, Sort from small to large

Zrevrangebyscore (name, max, Min, Start=none, Num=none, Withscores=false, Score_cast_func=float) : Gets the elements of the ordered collection of name corresponding to the range of fractions, sorted from large to small

127.0.0.1:6379> zadd Web 3 HTML 7 CSS JavaScript 4 php asp 6 aspx (integer) 6127.0.0.1:6379> zrangebyscore web 0) "HTML" 2) "PHP" 127.0.0.1:6379> zrevrangebyscore Web 101) "ASP" 2) "JavaScript"

Zcard (name): Gets the number of ordered collection elements that name corresponds to

127.0.0.1:6379> zadd Web 3 HTML 7 CSS JavaScript 4 php asp 6 aspx (integer) 6127.0.0.1:6379> zcard web (integer) 6

Zcount (name, Min, max): Gets the number of fractions between Min and Max in the ordered collection of name

127.0.0.1:6379> zadd Web 3 HTML 7 CSS JavaScript 4 php asp 6 aspx (integer) 6127.0.0.1:6379> zcount Web Ten (i Nteger) 2

Zincrby (name, amount, value): The fractional value corresponding to the ordinal set of the increment name

127.0.0.1:6379> zrange Web 0-1 withscores 1) "HTML" 2) "3" 3) "PHP" 4) "4" 5) "aspx" 6) "6" 7) "CSS" 8) "7" 9) "Javasc Ript "ten") "ASP" "127.0.0.1:6379> Zincrby Web 2 css" 9 "127.0.0.1:6379> zrange Web 0-1 withscores 1)" htm L "2)" 3 "3)" PHP "4)" 4 "5)" aspx "6)" 6 "7)" CSS "8)" 9 "9)" JavaScript ")" "" 12 "" ASP "15"

Zrank (name, value): Gets the rank of value in the ordered collection of name, from small to large, the first bit is 0

Zrevrank (name, value): Gets the rank of value in the ordered collection of name, from large to small, with the first bit 0

127.0.0.1:6379> zrange Web 0-1 withscores 1) "HTML" 2) "3" 3) "PHP" 4) "4" 5) "aspx" 6) "6" 7) "CSS" 8) "9" 9) "Javasc Ript "ten") "ASP" "127.0.0.1:6379> Zrank Web php (integer) 1127.0.0.1:6379> zrevrank web php (integer) 4

Zrem (name, values): Removes values from the ordered collection of name

127.0.0.1:6379> zrange Web 0-1 withscores 1) "HTML" 2) "3" 3) "PHP" 4) "4" 5) "aspx" 6) "6" 7) "CSS" 8) "9" 9) "Javasc Ript "ten") "ASP" "127.0.0.1:6379> Zrem Web aspx css (integer) 2127.0.0.1:6379> zrange web 0-1 withscores 1) "HTML" 2) "3" 3) "PHP" 4) "4" 5) "JavaScript" 6) "7" "ASP" 8) "15"

Zremrangebyrank (name, Min, max): Delete based on line range

127.0.0.1:6379> zrange Web 0-1 withscores 1) "HTML" 2) "3" 3) "PHP" 4) "4" 5) "aspx" 6) "6" 7) "CSS" 8) "7" 9) "Javasc Ript "ten") "ASP" "127.0.0.1:6379> Zremrangebyrank Web 0 2 (integer) 3127.0.0.1:6379> zrange Web 0-1 with scores1) "CSS" 2) "7" 3) "JavaScript" 4) "5" "ASP" 6) "15"

Zremrangebyscore (name, Min, max): Delete based on score range

127.0.0.1:6379> zrange Web 0-1 withscores 1) "HTML" 2) "3" 3) "PHP" 4) "4" 5) "aspx" 6) "6" 7) "CSS" 8) "7" 9) "Javasc Ript "ten") "ASP" "127.0.0.1:6379> Zremrangebyscore Web 0 5 (integer) 2127.0.0.1:6379> zrange web 0-1 Wit hscores1) "aspx" 2) "6" 3) "CSS" 4) "7" 5) "JavaScript" 6) "7" "ASP" 8) "15"

Zscore (name, value): Gets the fraction of value corresponding to the ordered collection of name

127.0.0.1:6379> zrange Web 0-1 withscores1) "aspx" 2) "6" 3) "CSS" 4) "7" 5) "JavaScript" 6) "(7)" ASP "8)" 15 "127.0.0.1:6 379> zscore Web css "7"

Zinterstore (dest, number, keys, Aggregate=none): Gets the intersection of number ordered collections and is deposited into the Dest collection, and if different fractions of the same value are encountered, follow the aggregate. The value of the aggregate is: Sum,min,max

127.0.0.1:6379> zrange Web 0-1 withscores 1) "HTML" 2) "3" 3) "PHP" 4) "4" 5) "aspx" 6) "6" 7) "CSS" 8) "7" 9) "Javasc  Ript "ten") "ASP" ("2") "3" (127.0.0.1:6379> zrange name 0-1 withscores 1) "John" (3) "Jane" 4) "7" 5) "PHP" 6) "9" 7) "Jack" 8) "(9)" Andy ")" (")" "CSS" (+) "127.0.0.1:6379>" Zinterstore web_name 2 Web name (integer) 2127. 0.0.1:6379> zrange web_name 0-1 withscores1) "PHP" 2) "3" "CSS" 4) "39"

Zunionstore (dest, number, keys, Aggregate=none): Gets the set of number ordered collections, and if different fractions of the same value are encountered, then the value of aggregate is: SUM, Min,max

127.0.0.1:6379> zrange Web 0-1 withscores 1) "HTML" 2) "3" 3) "PHP" 4) "4" 5) "aspx" 6) "6" 7) "CSS" 8) "7" 9) "Javasc  Ript "ten") "ASP" ("2") "3" (127.0.0.1:6379> zrange name 0-1 withscores 1) "John" (3) "Jane" 4) "7" 5) "PHP" 6) "9" 7) "Jack" 8) "(9)" Andy ")" (")" CSS "()" + "127.0.0.1:6379> zunionstore web_name 2 Web name (integer) 10127 .0.0.1:6379> zrange web_name 0-1 withscores 1) "HTML" 2) "3" 3) "John" 4) "3" 5) "aspx" 6) "6" 7) "Jane" 8) "7" 9) "Ja CK "Ten") "(one)" JavaScript "()") "(PHP)" () ")" (")") "(") "" (ASP) ")" (")") "(") "" (")" "(") "(" 20 ")" 39 "

Zscan (name, cursor=0, Match=none, Count=none, score_cast_func=float): matches the value in the ordered collection corresponding to name

Zscan_iter (name, Match=none, count=none,score_cast_func=float): Iterative Matching

127.0.0.1:6379> zrange Web 0-1 withscores 1) "HTML" 2) "3" 3) "PHP" 4) "4" 5) "aspx" 6) "6" 7) "CSS" 8) "7" 9) "Javasc Ript "ten") "ASP" "0" (Zscan Web 0 match *a*1) "127.0.0.1:6379>" 2) 1) "aspx"   2) "6"   3) "JavaScript" 
   4) "5" "   ASP"   6) "15"

Set operation of Python-redis

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.