Redis简介

Redis 是一个开源(BSD许可)的,内存中的数据结构存储系统,它可以用作数据库、缓存和消息中间件。 它支持多种类型的数据结构,如 字符串(strings), 散列(hashes), 列表(lists), 集合(sets), 有序集合(sorted sets) 与范围查询, bitmaps, hyperloglogs 和地理空间(geospatial) 索引半径查询。 Redis 内置了 复制(replication),LUA脚本(Lua scripting), LRU驱动事件(LRU eviction),事务(transactions) 和不同级别的 磁盘持久化(persistence), 并通过 Redis哨兵(Sentinel)和自动 分区(Cluster)提供高可用性(high availability)。
Linux 下安装
下载地址:http://redis.io/download,下载最新文档版本。
本教程使用的最新文档版本为 4.0.1,下载并安装:
$ wget http://download.redis.io/releases/redis-4.0.1.tar.gz
$ tar -zvxf redis-4.0.1.tar.gz
$ cd redis-4.0.1
$ make
安装完后进行安装检验
$ make test

如果遇到Redis need tcl 8.5 or newer
$ make test
You need tcl 8.5 or newer in order to run the Redis test
make: *** [test] Error 1
安装下tcl
$ wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
$ tar xzvf tcl8.6.1-src.tar.gz
$ cd /tcl8.6.1/unix/
$ ./configure
$ make
$ make install
再次运行$ make test
启动Redis服务器端
$ cd src
$ ./redis-server

注意这种方式启动redis 使用的是默认配置。也可以通过启动参数告诉redis使用指定配置文件使用下面命令启动。
$ cd src
$ ./redis-server redis.conf
客户端连接
$ cd src
$ ./redis-cli
127.0.0.1:6379> set foo helloworld!
OK
127.0.0.1:6379> get foo
"helloworld!"

通过客户端关闭服务端
127.0.0.1:6379> SHUTDOWN
或者可以通过
kill -9 PID号
关闭服务器端

但是Redis不是在后台运行,做如下操作:将redis.conf中的daemonize的值改为yes

网友评论