Learn to install the Redis database to a server or computer (Windows version)

Redis is a memory-based open source database system that is widely used in web applications, message queues, caching, real-time statistics and other fields. It supports a variety of data structures, including strings, hash tables, lists, sets, ordered sets, etc., and provides a variety of operation commands.

The characteristics of Redis are as follows:

  1. Memory storage: Redis stores data in memory, with fast reading and writing speed and high performance.

  2. Rich data structures: Redis supports a variety of data structures, such as strings, hash tables, lists, sets, ordered sets, etc., to meet the needs of different scenarios.

  3. Supports multiple operations: Redis provides a variety of operation commands, such as read and write, delete, sort, etc., and supports transaction processing.

  4. Distributed support: Redis supports distributed architecture and can be deployed on multiple servers to improve the scalability and fault tolerance of the system.

  5. Security: Redis supports password verification, connection encryption and other security measures to protect data security.

  6. Stability: Redis has high stability and can run for a long time without restarting.

Redis application scenarios include caching, queues, rankings, counters, real-time analysis, etc. By using Redis, the performance, scalability and reliability of the system can be improved.

 1. Installation steps* (windows version)

Download the Windows installation package of Redis. Link: https://pan.baidu.com/s/1O17zhDAu1C6rw09FrKO2FQ?pwd=07ne Extraction code: 07ne

  1. Unzip the Redis installation package.

  2. Open the decompressed Redis folder and find redis-server.exethe file. Right-click redis-server.exethe file and select Run as administrator. Or double-click start.bat directly! The commands saved inside (redis-server.exe redis.windows.conf)

Hold down Shift and right-click the mouse in the empty space of the redis folder, click to open shell. In the command prompt window that pops up, enter the following command: redis-cli. Press Enter to check whether the service is started:

If the local computer IP127.0.0.1:6379 is returned, the startup is successful!

Note: This command window cannot be closed! Keep it on!

2. Configure the link password and port (usually no need to change)

At this point, the Windows version database has been installed. This database is different from SQLite (embedded databases do not need to be started separately, and the installation is completed). Most databases are not embedded databases, so they need to start the database separately! For example, Oracle\Mysql\Redis...all need to be started separately! 

If you must modify the IP, port, and password of the Redis database, open redis.windows.conf

 It is not recommended to modify the IP and port!

Add access password (default is no password), don’t waste anything: 

Add after this sentence #requirepass foobared

Only after the database is started can the code request and access, edit, delete, add, delete, modify, and check!

3. Case: NodeJS links redis database

Here is a list of Node.js code that requests to call the Redis database!

const Redis = require('ioredis'); // 创建 Redis 客户端  

//创建一个链接实例毕竟人家是个类,你只是用一下链接,括号里是构造函数,多个重载

const redis = new Redis(

{  

host: '这里输入你的远程服务器的 IP 地址如果是本地就不需要这一句或者填入127.0.0.1',  

port: 6379  // 远程服务器的 Redis 端口,默认都是6379 建议不要改

password:"你的redis密码" //如果没有在redis.windows.conf 文件中配置密码,就删除本语句

 }

);

// 连接成功时触发  

redis.on('connect', () => {   console.log('Connected to Redis');  });

// 连接错误时触发  

redis.on('error', (error) => {   console.error('Error connecting to Redis:', error);  });

// 设置键值对
// 设置键值对  
redis.set('key', 'value')  
 .then(() => {  
   console.log('Key-value pair is set');  
   // 获取键的值  
   return redis.get('key');  
 })  
 .then((value) => {  
   console.log('Retrieved value:', value);  
   // 关闭 Redis 连接  
   redis.quit();  
 })  
 .catch((error) => {  
   console.error('Redis operation failed:', error);  
   redis.quit();  
 });  

Congratulations on completing the installation and startup!

Guess you like

Origin blog.csdn.net/leoysq/article/details/133346144