简介(摘抄自官网)
Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes with radius queries and streams. Redis has built-in replication, Lua scripting, LRU eviction, transactions and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster.
翻译:
Redis开源、遵守BSD协议、支持内存中数据结构的存储、可以作为数据库使用、缓存或者消息代理。支持多种数据类型:string(字符串)、hashes(哈希)、lists(链表)、sets(集合)……Redis有内置复制(built-in replication)、LUA 脚本(Lua scripting)、LRU eviction,支持事务,可以提供不同级别的数据持久化功能、并且可以通过Redis哨兵(Sentinel)和Redis集群自动分区来达到高可用性
1、安装
-
进入Github下载最新版本的Redis,我用的版本是5.0.4;
-
下载后,将压缩包放到合适的文件夹中进行解压;
2、启动服务器
- 进入解压的根目录,打开cmd窗口
- 执行下列命令
redis-server.exe redis.windows.conf
- 界面显示类似一下内容表示服务器启动成功
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.2.100 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 2180
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
[2180] 23 Apr 22:34:23.782 # Server started, Redis version 3.2.100
[2180] 23 Apr 22:34:23.782 * The server is now ready to accept connections on port 6379
上述内容可以看出我们Redis启动默认使用的端口是6379
- 不要关闭服务器窗口
3、启动客户端,试手简单命令
- 保持在根目录不变,执行再打开一个cmd窗口,输入以下内容
./redis-cli.exe -h 127.0.0.1 -p 6379
- 存放并查看String类型数据
127.0.0.1:6379> set name wangming
OK
127.0.0.1:6379> get name
"wangming"
- 存放并查看Hash类型数据
127.0.0.1:6379> hmset mymsg name "xiaoming" age 20
OK
127.0.0.1:6379> hgetall mymsg
1) "name"
2) "xiaoming"
3) "age"
4) "20"
127.0.0.1:6379> hget mymsg name
"xiaoming"
127.0.0.1:6379> hget mymsg age
"20"
- 存放并查看List链表类型数据
127.0.0.1:6379> lpush grades 99 100 80 70
(integer) 4
127.0.0.1:6379> llen grades
(integer) 4
127.0.0.1:6379> lindex grades 0
"70"
127.0.0.1:6379> lrange grades 0 4
1) "70"
2) "80"
3) "100"
4) "99"
127.0.0.1:6379> lrange grades 1 4
1) "80"
2) "100"
3) "99"
- 存放并查看Set集合类型数据
127.0.0.1:6379> sadd students xiaoming wangli myt cgj
(integer) 4
127.0.0.1:6379> smembers students
1) "cgj"
2) "myt"
3) "wangli"
4) "xiaoming"
127.0.0.1:6379> scard students
(integer) 4