从源代码安装Redis并进行简单使用

我将介绍一种从源代码将Redis安装到CentOS并仅使用一小部分的方法。

开始解冻

点击位于下面URL右侧的「下载」按钮,获取tarball。
http://redis.io/download

如果使用wget,
$ wget http://download.redis.io/releases/redis-2.8.19.tar.gz

解压 tarball
$ tar zxf redis-2.8.19.tar.gz

可以建设/构建

因为Redis中没有configure脚本,所以需要在Redis的顶级目录下执行make。

$ cd redis-2.8.19
$ make
$ su -
# make install

试用一下

服务器启动

使用redis-server命令启动Redis。
$ redis-server
如果出现以下内容,则表示启动成功。默认将在6379端口上运行。

[26047] 20 Dec 23:47:33.766 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
[26047] 20 Dec 23:47:33.768 * Increased maximum number of open files to 10032 (it was originally set to 4864).
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 2.8.19 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in stand alone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 26047
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

[26047] 20 Dec 23:47:33.770 # Server started, Redis version 2.8.19
[26047] 20 Dec 23:47:33.779 * DB loaded from disk: 0.009 seconds
[26047] 20 Dec 23:47:33.779 * The server is now ready to accept connections on port 6379

客户连接

我們實際上進行set和get操作試試看。連接到redis-server時,我們使用redis-cli。

$ redis-cli
127.0.0.1:6379> set hoge 123
OK
127.0.0.1:6379> get hoge
"123"