search
HomeDatabaseMysql Tutorial 搞一些好玩的东西redis

日常开发中,总会接触到一些好玩的东西,比如这篇的redis,一说到redis,可能就有人跟memcache做比较了,是呀, memcache只能说是简单的kv内存数据结构,而redis支持的数据类型就丰富多了,当然最能让人看上眼的就是SortedSet。 有了它,我们就可以玩一些贪心

 

     日常开发中,总会接触到一些好玩的东西,比如这篇的redis,一说到redis,可能就有人跟memcache做比较了,是呀,

memcache只能说是简单的kv内存数据结构,而redis支持的数据类型就丰富多了,当然最能让人看上眼的就是SortedSet。

有了它,我们就可以玩一些“贪心”的问题,网站空间,比如适合“贪心”的优先队列,说到优先队列,我们以前实现了仅仅是内存形式的,香港虚拟主机,

哎,内存毕竟是内存,当有海量数据的时候,最好能有一个序列化到硬盘的操作。。。恰恰这个场景redis就可以办到。。。

一:快速搭建

    好了,网站空间,我们知道redis比较适合做的事情了,现在我们可以进行快速搭建。

第一步:下载redis-2.0.2.zip (32 bit)。然后改名为redis放在D盘中。

 

最重要的也就是下面两个:

redis-server.exe:        这个就是redis的服务端程序。

redis-cli.exe:             服务端开启后,我们的客户端就可以输入各种命令测试了。

从图中我们可以看到两点:

①:没有指定config file。

     原来redis建议我们做一个配置文件,那我就搞段配置。

daemonize:  是否以“守护进程”的方式开启,当是守护进程的时候就不受控制台的影响了。

logfile:         log文件位置。

database:    开启数据库的个数。

dbfilename:  数据快照文件名。

save * *:     保存快照的频率,第一个为时间,第二个为写操作。

将这些配置好后,我们再看看:

②:我们看到redis默认的开放端口为6379。

 

二:安装驱动

好了,redis已经搭建完毕了,现在我们就要用C#去操作redis,这也是我最渴望的功能,优先队列~,先下载C#驱动,

就可以看到如下3个dll。

最后我们做下小测试:

1 class Program 2 { Main(string[] args) 4 { , 6379); s = client.AddItemToSortedSet(, , 400); , , 300); , , 200); , , 100); , , 500); list = client.GetRangeFromSortedSet(, 0, 0); (var item in list) 19 { 20 Console.WriteLine(item); 21 } list = client.GetRangeFromSortedSetDesc(, 0, 0); (var item in list) 27 { 28 Console.WriteLine(item); 29 } 30 31 Console.Read(); 32 } 33 }

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
What Are the Limitations of Using Views in MySQL?What Are the Limitations of Using Views in MySQL?May 14, 2025 am 12:10 AM

MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

Securing Your MySQL Database: Adding Users and Granting PrivilegesSecuring Your MySQL Database: Adding Users and Granting PrivilegesMay 14, 2025 am 12:09 AM

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

What Factors Influence the Number of Triggers I Can Use in MySQL?What Factors Influence the Number of Triggers I Can Use in MySQL?May 14, 2025 am 12:08 AM

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

MySQL: Is it safe to store BLOB?MySQL: Is it safe to store BLOB?May 14, 2025 am 12:07 AM

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

MySQL: Adding a user through a PHP web interfaceMySQL: Adding a user through a PHP web interfaceMay 14, 2025 am 12:04 AM

Adding MySQL users through the PHP web interface can use MySQLi extensions. The steps are as follows: 1. Connect to the MySQL database and use the MySQLi extension. 2. Create a user, use the CREATEUSER statement, and use the PASSWORD() function to encrypt the password. 3. Prevent SQL injection and use the mysqli_real_escape_string() function to process user input. 4. Assign permissions to new users and use the GRANT statement.

MySQL: BLOB and other no-sql storage, what are the differences?MySQL: BLOB and other no-sql storage, what are the differences?May 13, 2025 am 12:14 AM

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

MySQL Add User: Syntax, Options, and Security Best PracticesMySQL Add User: Syntax, Options, and Security Best PracticesMay 13, 2025 am 12:12 AM

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

MySQL: How to avoid String Data Types common mistakes?MySQL: How to avoid String Data Types common mistakes?May 13, 2025 am 12:09 AM

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

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 Article

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

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.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor