search
HomeDatabaseMysql TutorialRedis数据库(set类型和zset类型)

set是一个集合,它是string类型的无序集合,set是通过hash table实现的,添加,删除,查找的时间复杂度都是O(1),对于集合我们可

一.set类型

set是一个集合,它是string类型的无序集合,,set是通过hash table实现的,添加,删除,查找的时间复杂度都是O(1),对于集合我们可以取并集,交集,差集。通过这些操作我们可以实现SNS中好友推荐和Blog的tag功能。

set常见操作:

(1)sadd

向一个集合中添加一个元素。例如:sadd set1 Hello

(2)smembers

查看集合中的所有元素。例如:smembers set1

(3)srem

删除集合中一个指定的元素。例如:srem set1 Hello

(4)spop

随机弹出set集合中德一个元素。例如:spop set1

(5)sdiff

求两个集合的差集,比如sdiff set1 set2,表示保留set1中与set2不同的所有元素。

(6)sdiffstore

将返回的差集存进一个集合。例如:sdiffstore set3 set1 set2,表示把set1与set2的差集存进

集合set3。

(7)sinter

返回给定两个集合的交集。例如:sinter set1 set2,表示返回set1和set2的交集。

(8)sinterstore

将两个集合的交集存进一个集合。例如:sinterstore set3 set1 set2,表示把set1和set2的交集

存进集合set3。

(9)sunion

返回给定两个集合的并集。例如:sunion set1 set2,表示返回set1和set2的并集。

(10)sunionstore

将两个集合的并集存进一个集合。例如:sunionstore set3 set1 set2,表示把set1和set2的并集

存进集合set3

(11)smove

从第一个key对应的set中移除member并添加到第二个对应的集合中。

例如:smove set1 set2 Hello,表示把set1中的Hello元素移动到set2中。

(12)scard

返回key对应集合的元素的个数。例如:scard set1。

(13)sismember

判断某一个元素是否为集合的元素。比如:sismember set1 Hello,表示判断Hello是否为set1的中

的元素。

(14)srandmember

随机返回名称为key的set的一个元素。例如:srandmember set1。

二.zset类型

zset是在set的基础上增加了顺序,形成一个有序的集合。

zset的常见操作:

(1)zadd

向有序集合zset中增加一个元素。例如:zadd zset 1 Hello

(2)zrange

输出zset中指定范围内的的所有元素,按照score从小到大的顺序。

例如:zrange zset 0 -1 withscores,表示输出有序集合zset中所有的元素,并且输出顺序号。

(3)zrem

删除名称为key的zset集合中的元素member。例如:zrem set1 Hello。

(4)zincrby

把有序集合zset中的指定元素的序列号加上指定的值。例如:zincrby zset 4 Hello

(5)zrank

返回名称为key的zset集合中元素的排名,按照下标从小到大的排名。例如:zrank zset Hello。

(6)zrevrank

返回名称为key的zset集合中元素的排名,按照下表从大到小的排名。例如:zrevrank zset Hello。

(7)zrevrange

按照score从大到小的顺序输出集合中所有元素。例如:zrevrange zset 0 -1 withscores。

(8)zrangebyscore

返回集合中给定区间的元素。例如:zrangebyscore zset 2 3 withscores

(9)zcount

返回集合中score在给定区间的数量。zcount zset 2 3

(10)zcard

返回集合中元素的个数。

(11)zremrangebyrank

按照索引来删除给定区间的元素。例如:zremrangebyrank zset 1 2

(12)zremrangebyscore

删除score在指定范围内的元素。例如:zremrangebyscore zset 1 2

Ubuntu 14.04下Redis安装及简单测试

Redis集群明细文档

Ubuntu 12.10下安装Redis(图文详解)+ Jedis连接Redis

Redis系列-安装部署维护篇

CentOS 6.3安装Redis

Redis安装部署学习笔记

Redis配置文件redis.conf 详解

Redis 的详细介绍:请点这里
Redis 的下载地址:请点这里

本文永久更新链接地址:

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Explain the InnoDB Buffer Pool and its importance for performance.Explain the InnoDB Buffer Pool and its importance for performance.Apr 19, 2025 am 12:24 AM

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

MySQL vs. Other Programming Languages: A ComparisonMySQL vs. Other Programming Languages: A ComparisonApr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Learning MySQL: A Step-by-Step Guide for New UsersLearning MySQL: A Step-by-Step Guide for New UsersApr 19, 2025 am 12:19 AM

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL: Essential Skills for Beginners to MasterMySQL: Essential Skills for Beginners to MasterApr 18, 2025 am 12:24 AM

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL: Structured Data and Relational DatabasesMySQL: Structured Data and Relational DatabasesApr 18, 2025 am 12:22 AM

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL: Key Features and Capabilities ExplainedMySQL: Key Features and Capabilities ExplainedApr 18, 2025 am 12:17 AM

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

The Purpose of SQL: Interacting with MySQL DatabasesThe Purpose of SQL: Interacting with MySQL DatabasesApr 18, 2025 am 12:12 AM

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

MySQL for Beginners: Getting Started with Database ManagementMySQL for Beginners: Getting Started with Database ManagementApr 18, 2025 am 12:10 AM

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software