Redis
Linux
下载
安装、启动
这里解压到根目录下
tar xzf redis-3.2.1 -C /
cd /redis-3.2.1
make
src/redis-server
本地连接
src/redis-cli
Protected-mode
Redis protected-mode 是3.2 之后加入的新特性, 默认protected-mode是启用的, 当外网进行连接时会:
-DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside. Connection closed by foreign host.
按照上面的提示, 修改配置文件protected-mode, bind或设置密码requirepass 好像不知道为什么没有效果
这里就在启动的时候增加参数 --protected-mode no
src/redis-server --protected-mode no
Windows
启动
切换到解压目录下, 执行 redis-server.exe redis.conf
命令行
操作 | 命令 | 备注 | |
---|---|---|---|
客户端连接 | redis-cli | 为了方便连接可以apt-get install redis-tools ,这样不需要每次进到安装文件下执行命令了 |
|
set值 | set mykey "value" |
||
查找特定模式pattern 的keys | keys patten |
||
get值 | get mykey |
||
delete 指定key | del key1 key2 |
参考
- Redis 主页 http://redis.io/
- Redis 命令行 http://redis.io/commands
- Redis 中文网 http://www.redis.net.cn/