Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Redis collection how to use Set

Shulou Source: shulou.com Published: 2022-06-01 04:59:16 09月26日 Update

Editor to share with you how to use the Redis collection Set, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Redis Collection (Set)

Single-valued multiple Value

1.sadd/smembers/sismember

Sadd: addin

Smembers: viewin

Sismember: determine whether it exists or not

127.0.0.1 sadd set011 9736 > smembers set011) 3127.0.1 smembers set011) "1" 2) "2" 3) "3" 127.0.1 sismember set011 (integer) 1127.0.1 VR 9736 > sismember set01 x (integer) 02. Scard, get the number of elements in the collection 127.0.0.1 integer 9736 > scard set01 (integer) 33. Srem key value deletes elements from the collection 127.0.0.1 integer 9736 > srem set01 3 (integer) 1127.0.1 integer 9736 > smembers set011) "1" 2) "2" 4. Srandmember key an integer (randomly selected numbers) 127.0.0.1 srandmember key 9736 > sadd set021 2 3 4 56 7 (integer) 7127.0.0.1 integer 9736 > smembers set021) "1" 2) "2" 3) "3" 4) "4" 5) "5" 6) "6" 7) "7" 127.0.1) SRANDMEMBER set02 31) "2" 2) "3" 3) "5" 5. Spop key random stack 127.0.0.1 spop set02 9736 > SMEMBERS set021) "1" 2) "2" 3) "3" 4) "4" 5) "5" 6) "7" 6. The function of key2 in key1 is to assign a value in key1 to key2127.0.0.1:9736 > SMOVE set02 set03 4 (integer) 1127.0.0.1) 9736 > SMEMBERS set021) "1" 2) "2" 3) "3" 4) "5" 5) "7" 127.0.0.1 key1 9736 > SMEMBERS set031) "x" 2) "z" 3) "4" 4) "y" 127.0.0.1 key1 9736 > 7. Mathematical set Class difference set: sdiff

Items in the first set but not in any subsequent set

127.0.1 SADD set01 9736 > SADD set021 123 4 5 (integer) 5127.0.1 SADD set021 2 a b (integer) 5127.0.1 SADD set021 9736 > SDIFF set01 set021) "4" 2) "5" 8. Mathematical set class intersection: sinter127.0.0.1:9736 > SINTER set01 set021) "1" 2) "2" 3) "3" 9. Mathematical set class union: sunion127.0.0.1:9736 > SUNION set01 set021) "b" 2) "2" 3) "1" 4) "5" 5) "3" 6) "4" 7) "a" above are all the contents of this article "how to use Redis set Set". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Mathematics articles number elements content not much intersection function most difference integers more knowledge industry information information channels face channels references learning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Linux Shulou Tech Info macOS MariaDB