table of Contents
I. Introduction
Redis is an open source (BSD license), the data structure stored in the memory system that can be used as a database, cache and messaging middleware. It supports multiple types of data structures, such as strings (strings), hashes (hashes), lists (lists), the set (sets), ordered collection (sorted sets) and range queries, bitmaps, hyperloglogs and geospatial ( geospatial) radius of the index query. Redis built-in replication (replication), LUA scripting (Lua scripting), LRU-driven events (LRU eviction), transaction (transactions) and different levels of disk persistence (persistence), and by Redis Sentinel (Sentinel) and automatic partitioning (Cluster ) provides high availability (high availability). [Introduction source Redis Chinese official website]
Two, Windows installation under
-
Redis Download
Since Redis not officially support Windows, but because it is open source, Microsoft's open technology team to develop and maintain a Windows interface program for Win64, providing a windows version of redis branch, has not updated maintained.
Download: https://github.com/microsoftarchive/redis/releases
-
Create a directory (the directory at random, according to custom, I put the D drive:
D:\Redis
) for decompressing files stored
contents after extracting as follows:
-
Open cmd window, enter
D:\Redis
the directory (just install directory)C:\Users>D: D:\>cd Redis D:\Redis>
Or directly in just
D:\Redis
directly into the cmd window directory
-
运行Redis
输入命令redis-server.exe redis.windows.conf
D:\Redis>redis-server.exe redis.windows.conf [9380] 21 Dec 20:12:21.137 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server.exe /path/to/redis.conf _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 3.2.100 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 9380 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' [9380] 21 Dec 20:12:21.143 # Server started, Redis version 3.2.100 [9380] 21 Dec 20:12:21.143 * DB loaded from disk: 0.000 seconds [9380] 21 Dec 20:12:21.143 * The server is now ready to accept connections on port 6379
1.可以把 redis 的路径(安装路径:
D:\Redis
)加到系统的环境变量里,这样就可以在任意目录下启动了
2.后面的那个redis.windows.conf
可以省略,会启用默认的
-
简单使用
(1)另启一个 cmd 窗口,原来的不要关闭,不然就无法访问服务端了
(2)进入redis目录下(添加过环境变量的不需要进入redis目录)
(3)连接Redis服务器redis-cli.exe -h 127.0.0.1 -p 6379
(4)设置键值对
set myKey myValue
(5)取出键值对
get myKey
三、Linux(Centos7)下安装
-
Redis下载
下载地址:https://redis.io/download,最好下载最新稳定版本,我下载的时候最新版本为
5.0
(1)获取对应版本的下载链接
(2)使用wget下载Redis安装包[root@localhost Redis]# wget http://download.redis.io/releases/redis-5.0.7.tar.gz [root@localhost Redis]# tar xzf redis-5.0.7.tar.gz [root@localhost Redis]# cd redis-5.0.7/ [root@localhost redis-5.0.7]# make
-
启动redis的三种方式
第一种方式:直接启动Redis[root@localhost redis-5.0.7]# ./src/redis-server
这种方式启动Redis 使用的是默认配置。也可以通过启动参数告诉Redis使用指定配置文件使用下面命令启动:
./src/redis-server ./redis.conf
第二种方式:以后台进程方式启动Redis
修改redis.conf文件
将daemonize no
修改为daemonize yes
[root@localhost redis-5.0.7]# ./src/redis-server ./redis.conf
查看进程:
ps -aux | grep redis
关闭进程:kill 进程id
第三种方式:设置Redis开机自启动
首先必须确保将daemonize no
修改为daemonize yes
,修改方法请看第二种方式
在/etc目录下新建redis目录[root@localhost redis-5.0.7]# cd /etc/ [root@localhost etc]# mkdir redis
The
安装目录
copy of a file to redis.conf in / etc / redis directory, and named 6379.conf[root@localhost etc]# cd redis/ [root@localhost redis]# cp /home/Redis/redis-5.0.7/redis.conf /etc/redis/6379.conf
The startup script copy of a Redis into /etc/init.d directory and renamed
redisd
[root@localhost redis]# cd /etc/init.d/ [root@localhost init.d]# cp /home/Redis/redis-5.0.7/utils/redis_init_script /etc/init.d/redisd
Modify
redisd
documents in the two paths[root@localhost init.d]# vim redisd
My Redis installation path is
/home/Redis/redis-5.0.7
, so I revised as follows:
If you do not make changes here, at startup will complain: Please No such file or directory, detailed error contents reference:: /etc/init.d/redisd: line 28: / usr / local / bin / redis-server error (/etc/init.d/redisd: line 28: / usr / local / bin / redis-server: No such file or directory) solution
Set redis boot from the start
[root@localhost init.d]# chkconfig redisd on
Now you can directly startup and shutdown services redis in the form of
start:service redisd start
[root@localhost init.d]# service redisd start Starting Redis server... 14200:C 09 Dec 2019 21:17:50.133 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 14200:C 09 Dec 2019 21:17:50.133 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=14200, just started 14200:C 09 Dec 2019 21:17:50.133 # Configuration loaded [root@localhost init.d]#
shut down:
service redisd stop
[root@localhost init.d]# service redisd stop Stopping ... Redis stopped [root@localhost init.d]#
-
Simple to use
[root@localhost init.d]# cd /home/Redis/redis-5.0.7/ [root@localhost redis-5.0.7]# src/redis-cli 127.0.0.1:6379> set myKey myValue OK 127.0.0.1:6379> get myKey "myValue" 127.0.0.1:6379>
Common Operation Command:
Start Client:src/redis-cli
set the key to:set 键 值
acquired by the key values:get 键