redis初探

刚开始自己搭建redis,踩了很多的坑,现将遇到的问题整理如下:
1、安装,首先,如果是在linux上安装的话,只需要按照官网上的要求去安装即可。
Installation
Download, extract and compile Redis with:
$ wget http://download.redis.io/releases/redis-3.2.5.tar.gz$ tar xzf redis-3.2.5.tar.gz$ cd redis-3.2.5$ make
The binaries that are now compiled are available in the  src  directory. Run Redis with:
$ src/redis-server
You can interact with Redis using the built-in client:
$ src/redis-cliredis> set foo barOKredis> get foo"bar"
如果是在windows下安装的情况下,则需要去另外一个地址去下载,因为redis本身是没有windows版本的,只不过有个组织开发了一个windows版本的,如下:(这一段是拷贝的别人的)
项目地址是:
( 注意 : dist文件改变了下载地址:  https://github.com/MSOpenTech/redis/releases  )

在 Release 页面中,可以找到 msi 安装文件以及 .zip 文件(而且有3.0的beta版,请下拉查找)。
下载解压,没什么好说的,在解压后的bin目录下有以下这些文件:
[plain]   view plain   copy
 
  1. redis-benchmark.exe         #基准测试  
  2. redis-check-aof.exe         # aof  
  3. redis-check-dump.exe        # dump  
  4. redis-cli.exe               # 客户端  
  5. redis-server.exe            # 服务器  
  6. redis.windows.conf          # 配置文件  

启动命令: redis-server.exe redis.windows.conf 
[plain]   view plain   copy
 
  1. D:\Develop\redis-2.8.12>redis-server.exe redis.windows.conf  
  2. [7736] 10 Aug 21:39:42.974 #  
  3. The Windows version of Redis allocates a large memory mapped file for sharing  
  4. the heap with the forked process used in persistence operations. This file  
  5. will be created in the current working directory or the directory specified by  
  6. the 'dir' directive in the .conf file. Windows is reporting that there is  
  7. insufficient disk space available for this file (Windows error 0x70).  
  8.   
  9. You may fix this problem by either reducing the size of the Redis heap with  
  10. the --maxheap flag, or by starting redis from a working directory with  
  11. sufficient space available for the Redis heap.  
  12.   
  13. Please see the documentation included with the binary distributions for more  
  14. details on the --maxheap flag.  
  15.   
  16. Redis can not continue. Exiting.  

根据提示,是 maxheap 标识有问题,打开配置文件  redis.windows.conf , 搜索  maxheap  , 然后直接指定好内容即可.
[plain]   view plain   copy
 
  1. .......  
  2. #    
  3. # maxheap <bytes>  
  4. maxheap 1024000000  
  5. .......  
然后再次启动,OK,成功.
[plain]   view plain   copy
 
  1. D:\work\redis-3.2.100>redis-server  redis.windows.conf  
  2.                 _._  
  3.            _.-``__ ''-._  
  4.       _.-``    `.  `_.  ''-._           Redis 3.2.1000 (00000000/0) 64 bit  
  5.   .-`` .-```.  ```\/    _.,_ ''-._  
  6.  (    '      ,       .-`  | `,    )     Running in stand alone mode  
  7.  |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379  
  8.  |    `-._   `._    /     _.-'    |     PID: 6731  
  9.   `-._    `-._  `-./  _.-'    _.-'  
  10.  |`-._`-._    `-.__.-'    _.-'_.-'|  
  11.  |    `-._`-._        _.-'_.-'    |           http://redis.io  
  12.   `-._    `-._`-.__.-'_.-'    _.-'  
  13.  |`-._`-._    `-.__.-'    _.-'_.-'|  
  14.  |    `-._`-._        _.-'_.-'    |  
  15.   `-._    `-._`-.__.-'_.-'    _.-'  
  16.       `-._    `-.__.-'    _.-'  
  17.           `-._        _.-'  
  18.               `-.__.-'  
  19.   
  20. [6736] 10 Nov 16:01:22.247 # Server started, Redis version 3.2.100  
  21. [6736] 10 Nov 16:01:22.248 * The server is now ready to accept connections on port 6379  

然后可以使用自带的客户端工具进行测试。
双击打开  redis-cli.exe  , 如果不报错,则连接上了本地服务器,然后测试,比如 set命令,get命令:

  1. 127.0.0.1:6379> set test qqqq   
  2. OK  
  3. 127.0.0.1:6379> get test
  4. "qqqq"  
  5. 127.0.0.1:6379>  

如果需要帮助,可以在 cli窗口中输入 help查看,例如:
127.0.0.1:6379> help  

2、关于在使用过程中踩的坑

redis默认是只允许本地连接,如果想要在外部调用,则会报connection refused,如下图:

所以需要在redis.conf中把bind的本地ip给注释掉,或者绑定对应的外部的ip地址,另外如果允许的客户端够多的话,对内存有一定的要求,如果没有那么多的内存的话需要将maxclint的数目改小一点。
再者还有一个问题,redis默认是开启保护模式的,如果外部想要连接,需要将保护模式去掉,或者绑定0.0.0.0这个ip地址,或者是设置用户名和密码
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值