Redis基础

  1. 安装
  2. 启动
    redis-server; (默认地址127.0.0.1, port:6379)
    redis-server –port 6380(修改启动端口)
    通过初始化脚本启动:utils/redis_init_script:包含redis-server的主要配置,可以修改,也可以从后面的通过参数修噶
  3. 停止
    强制终止会导致缓存数据丢失
    redis-cli SHUTDOWN:正常关闭,首先会断开所有客户端连接,然后持久化内存中的数据到磁盘
  4. redis-cli客户端连接
    (1)redis-cli -h <ip addr> -p <port number> — 远程连接redis server
    (2)不带参数执行redis-cli, 进入交互模式,可以发多条命令
  5. redis-cli命令返回值
    (1)返回状态:set值返回ok,ping返回pong等
    (2)输入错误命令:提示 unknown command “<错误命令串>”
    (3)返回整数值:incr(返回递增键值);dbsize;
    (4)字符串回复:get — 获取key的value为字符串的值
    (5)多行字符串回复:keys * — 按照一定规则返回符合规则的键值列表
  6. 配置
    (1)可以修改redis.conf或者redis.windows.conf文件,启动的时候作为参数传入
    (2)redis server已经启动了,可以即使修改属性,如config set loglevel warning
  7. 多数据库
    select <编号> –切换到某个编号的数据库,redis不存在数据库名,不支持一个实例里面不同数据库用不同的权限,多个数据库之间没有完全隔离,所以最好不用业务来分库,可以根据不同环境分库,如开发环境,测试环境等。

Redis启动错误

D:\redis-2.8.17>redis-server.exe redis.windows.conf
[4692] 27 Nov 12:14:05.995 #
The Windows version of Redis allocates a memory mapped heap for sharing with
the forked process used for persistence operations. In order to share this
memory, Windows allocates from the system paging file a portion equal to the
size of the Redis heap. At this time there is insufficient contiguous free
space available in the system paging file for this operation (Windows error
0x5AF). To work around this you may either increase the size of the system
paging file, or decrease the size of the Redis heap with the --maxheap flag.
Sometimes a reboot will defragment the system paging file sufficiently for
this operation to complete successfully.

Please see the documentation included with the binary distributions for more
details on the --maxheap flag.

Redis can not continue. Exiting.

解决方案:redis.windows.conf中增加 maxheap 1024000000