search
HomeDatabaseMysql TutorialRedis入门基础教程

Redis是一个开源,先进的key-value存储,并用于构建高性能,可扩展的Web应用程序的完美解决方案。Redis是一个多实用的工具,可以

Redis是一个开源,先进的key-value存储,并用于构建高性能,可扩展的Web应用程序的完美解决方案。

Redis从它的许多竞争继承来的三个主要特点:

  • Redis数据库完全在内存中,使用磁盘仅用于持久性。

  • 相比许多键值数据存储,Redis拥有一套较为丰富的数据类型。

  • Redis可以将数据复制到任意数量的从服务器。

  • Redis 优势
  • 异常快速:Redis的速度非常快,每秒能执行约11万集合,每秒约81000+条记录。

  • 支持丰富的数据类型:Redis支持最大多数开发人员已经知道像列表,集合,有序集合,散列数据类型。这使得它非常容易解决各种各样的问题,因为我们知道哪些问题是可以处理通过它的数据类型更好。

  • 操作都是原子性:所有Redis操作是原子的,这保证了如果两个客户端同时访问的Redis服务器将获得更新后的值。

  • 多功能实用工具:Redis是一个多实用的工具,可以在多个用例如缓存,消息,队列使用(Redis原生支持发布/订阅),任何短暂的数据,应用程序,如Web应用程序会话,网页命中计数等。

  • Ubuntu 14.04下Redis安装及简单测试

    Redis集群明细文档

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

    Redis系列-安装部署维护篇

    Redis入门教程 

    CentOS 6.3安装Redis

    Redis安装部署学习笔记

    Redis配置文件redis.conf 详解

    Redis - 环境

    Ubuntu上安装Redis,打开终端,然后键入以下命令:

     

    $sudo apt-get update $sudo apt-get install redis-server

    这将在您的计算机上安装Redis。

    启动 Redis

    $redis-server

    检查Redis是否在工作?

    $redis-cli

    这将打开一个Redis提示,如下图所示:

    redis 127.0.0.1:6379>

    上面的提示127.0.0.1是本机的IP地址,6379为Redis服务器运行的端口。现在输入PING命令,如下图所示。

    redis 127.0.0.1:6379> ping PONG

    这说明你已经成功地安装Redis在您的机器上。

    在Ubuntu上安装Redis的桌面管理器

    在Ubuntu上安装Redis的桌面管理器,只需从 打开下载软件包并安装它。

    Redis桌面管理器会给你用户界面来管理Redis的Key和数据。

    Redis - 数据类型

    Redis支持5种类型的数据类型,它描述如下的:

    字符串

    Redis字符串是字节序列。Redis字符串是二进制安全的,这意味着他们有一个已知的长度没有任何特殊字符终止,所以你可以存储任何东西,512兆为上限。

    例子

    上面是Redis的set和get命令的例子,Redis名称为yiibai使用的key存储在Redis的字符串值。

    哈希

    Redis的哈希是键值对的集合。 Redis的哈希值是字符串字段和字符串值之间的映射,因此它们被用来表示对象

    例子 1) "username" 2) "yiibai" 3) "password" 4) "yiibai" 5) "points" 6) "200"

    在上面的例子中的哈希数据类型,用于存储其中包含的用户的基本信息用户的对象。这里HMSET,HEGTALL用户命令user:1是键。

    列表

    Redis的列表是简单的字符串列表,排序插入顺序。您可以添加元素到Redis的列表的头部或尾部。

    例子 1) "rabitmq" 2) "mongodb" 3) "redis"

    列表的最大长度为 232 - 1 元素(4294967295,每个列表中可容纳超过4十亿的元素)。

    集合

    Redis的集合是字符串的无序集合。在Redis您可以添加,删除和测试文件是否存在,在成员O(1)的时间复杂度。

    例子 1) "rabitmq" 2) "mongodb" 3) "redis"

    注意:在上面的例子中rabitmq集合添加加两次,但由于集合元素具有唯一属性。

    集合中的元素最大数量为 232 - 1 (4294967295,可容纳超过4十亿元素)。

    有序集合

    Redis的有序集合类似于Redis的集合,字符串不重复的集合。不同的是,一个有序集合的每个成员用分数,以便采取有序set命令,从最小的到最大的成员分数有关。虽然成员具有唯一性,但分数可能会重复。

    例子 1) "redis" 2) "mongodb" 3) "rabitmq" Redis - keys

    Redis keys命令用于在Redis的管理键。Redis keys命令使用语法如下所示:

    语法 redis 127.0.0.1:6379> COMMAND KEY_NAME 例子

    在上面的例子中DEL是命令,而yiibai是key。如果key被删除,那么输出该命令将是(整数)1,否则它会是(整数)0

    Redis - Strings

    Redis strings命令用于在Redis的管理字符串值。Redis strings命令的使用语法,如下所示:

    语法 redis 127.0.0.1:6379> COMMAND KEY_NAME 例子

    在上面的例子SET和GET是命令,而yiibai是key。

    Redis - 哈希

    Redis的哈希值是字符串字段和字符串值之间的映射,所以他们是代表对象的完美数据类型

    在Redis的哈希值,最多可存储超过400十亿字段 - 值对。

    例子 1) "name" 2) "redis tutorial" 3) "description" 4) "redis basic commands for caching" 5) "likes" 6) "20" 7) "visitors" 8) "23000"

    在上面的例子中,已经在哈希命名yiibai的Redis集合名为tutorials(name, description, likes, visitors)

    Redis - 列表

    Redis的列表是简单的字符串列表,,排序插入顺序。您可以添加Redis元素在列表头部或列表的尾部。

    列表的最大长度为 232 - 1 个元素(每个列表元素个数超过4294967295)。

    例子 1) "mysql" 2) "mongodb" 3) "redis"

    在上述例子中的三个值被插入在redis列表名为LPUSH的命令教程。

    Redis - 集合

    Redis的集合是唯一的字符串的无序集合。集合的唯一性不允许数据的重复的键。

    在Redis的集合添加,删除和测试文件是否存在成员在O(1)(常数时间不管里面包含的元素集合的数量)。集合的最大长度为 232 - 1 个元素(每集合超过4294967295元素)。

    例子 1) "mysql" 2) "mongodb" 3) "redis"

    在上述例子中的三个值被命令SADD插入redis的集合名称tutorials。

    Redis有序集

    Redis的有序集合类似Redis的集合存储在设定值具有唯一性。不同的是,一个有序集合的每个成员用分数,以便采取有序set命令,从最小的到最大的分数有关。

    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
    How to Grant Permissions to New MySQL UsersHow to Grant Permissions to New MySQL UsersMay 09, 2025 am 12:16 AM

    TograntpermissionstonewMySQLusers,followthesesteps:1)AccessMySQLasauserwithsufficientprivileges,2)CreateanewuserwiththeCREATEUSERcommand,3)UsetheGRANTcommandtospecifypermissionslikeSELECT,INSERT,UPDATE,orALLPRIVILEGESonspecificdatabasesortables,and4)

    How to Add Users in MySQL: A Step-by-Step GuideHow to Add Users in MySQL: A Step-by-Step GuideMay 09, 2025 am 12:14 AM

    ToaddusersinMySQLeffectivelyandsecurely,followthesesteps:1)UsetheCREATEUSERstatementtoaddanewuser,specifyingthehostandastrongpassword.2)GrantnecessaryprivilegesusingtheGRANTstatement,adheringtotheprincipleofleastprivilege.3)Implementsecuritymeasuresl

    MySQL: Adding a new user with complex permissionsMySQL: Adding a new user with complex permissionsMay 09, 2025 am 12:09 AM

    ToaddanewuserwithcomplexpermissionsinMySQL,followthesesteps:1)CreatetheuserwithCREATEUSER'newuser'@'localhost'IDENTIFIEDBY'password';.2)Grantreadaccesstoalltablesin'mydatabase'withGRANTSELECTONmydatabase.TO'newuser'@'localhost';.3)Grantwriteaccessto'

    MySQL: String Data Types and CollationsMySQL: String Data Types and CollationsMay 09, 2025 am 12:08 AM

    The string data types in MySQL include CHAR, VARCHAR, BINARY, VARBINARY, BLOB, and TEXT. The collations determine the comparison and sorting of strings. 1.CHAR is suitable for fixed-length strings, VARCHAR is suitable for variable-length strings. 2.BINARY and VARBINARY are used for binary data, and BLOB and TEXT are used for large object data. 3. Sorting rules such as utf8mb4_unicode_ci ignores upper and lower case and is suitable for user names; utf8mb4_bin is case sensitive and is suitable for fields that require precise comparison.

    MySQL: What length should I use for VARCHARs?MySQL: What length should I use for VARCHARs?May 09, 2025 am 12:06 AM

    The best MySQLVARCHAR column length selection should be based on data analysis, consider future growth, evaluate performance impacts, and character set requirements. 1) Analyze the data to determine typical lengths; 2) Reserve future expansion space; 3) Pay attention to the impact of large lengths on performance; 4) Consider the impact of character sets on storage. Through these steps, the efficiency and scalability of the database can be optimized.

    MySQL BLOB : are there any limits?MySQL BLOB : are there any limits?May 08, 2025 am 12:22 AM

    MySQLBLOBshavelimits:TINYBLOB(255bytes),BLOB(65,535bytes),MEDIUMBLOB(16,777,215bytes),andLONGBLOB(4,294,967,295bytes).TouseBLOBseffectively:1)ConsiderperformanceimpactsandstorelargeBLOBsexternally;2)Managebackupsandreplicationcarefully;3)Usepathsinst

    MySQL : What are the best tools to automate users creation?MySQL : What are the best tools to automate users creation?May 08, 2025 am 12:22 AM

    The best tools and technologies for automating the creation of users in MySQL include: 1. MySQLWorkbench, suitable for small to medium-sized environments, easy to use but high resource consumption; 2. Ansible, suitable for multi-server environments, simple but steep learning curve; 3. Custom Python scripts, flexible but need to ensure script security; 4. Puppet and Chef, suitable for large-scale environments, complex but scalable. Scale, learning curve and integration needs should be considered when choosing.

    MySQL: Can I search inside a blob?MySQL: Can I search inside a blob?May 08, 2025 am 12:20 AM

    Yes,youcansearchinsideaBLOBinMySQLusingspecifictechniques.1)ConverttheBLOBtoaUTF-8stringwithCONVERTfunctionandsearchusingLIKE.2)ForcompressedBLOBs,useUNCOMPRESSbeforeconversion.3)Considerperformanceimpactsanddataencoding.4)Forcomplexdata,externalproc

    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

    Safe Exam Browser

    Safe Exam Browser

    Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

    ZendStudio 13.5.1 Mac

    ZendStudio 13.5.1 Mac

    Powerful PHP integrated development environment

    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.

    PhpStorm Mac version

    PhpStorm Mac version

    The latest (2018.2.1) professional PHP integrated development tool

    MinGW - Minimalist GNU for Windows

    MinGW - Minimalist GNU for Windows

    This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.