实践Redis

installation

package manager

deepin 15.11

1
$ sudo apt install redis-server

source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 解压
$ tar zxvf redis-4.0.6.tar.gz
# 编译
$ cd redis-4.0.6
$ make

# 启动(前台模式)
$ src/redis-server 
24087:C 18 Dec 14:52:01.956 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
24087:C 18 Dec 14:52:01.956 # Redis version=4.0.6, bits=64, commit=00000000, modified=0, pid=24087, just started
24087:C 18 Dec 14:52:01.956 # Warning: no config file specified, using the default config. In order to specify a config file use src/redis-server /path/to/redis.conf
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 4.0.6 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 24087
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

24087:M 18 Dec 14:52:01.958 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
24087:M 18 Dec 14:52:01.958 # Server initialized
24087:M 18 Dec 14:52:01.958 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
24087:M 18 Dec 14:52:01.958 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
24087:M 18 Dec 14:52:01.958 * Ready to accept connections

指定配置文件运行

1
$ src/redis-server redis.conf

配置文件redis.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
bind=10.10.26.22
port 6379
# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
# 是否daemon模式,如果一台机器运行多个redis,建议非daemon模式(不需要pid file),这样就没有pid file重复的问题
daemonize no

# If a pid file is specified, Redis writes it where specified at startup
# and removes it at exit.
#
# When the server runs non daemonized, no pid file is created if none is
# specified in the configuration. When the server is daemonized, the pid file
# is used even if not specified, defaulting to "/var/run/redis.pid".
#
# Creating a pid file is best effort: if Redis is not able to create it
# nothing bad happens, the server will start and run normally.
# 
pidfile /var/run/redis/redis-server.pid

设计

实体分层

由上至下依次是:

  • 实例(instance)

    对应redis 进程

  • 库(database)

    默认16个,默认使用编号为0的database,可以配置

  • 键值(Key-Value)

集群

GUI client

Redis Desktop Manager

参考

Redis命令参考