Redis教程

简介

  • REmote DIctionary Server(Redis) 是一个由Salvatore Sanfilippo写的key-value存储系统。
  • 基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API。

关系型数据库查询大数据

  • data page 大小:4k
  • 索引index 大小:4k

与memcached区别?

  • 只支持字符串
  • 开源的BSD协议, 使用ANSI C编写, 基于目的吗支持持久化, 高性能的key-value的NoSQL数据库
  • 支持数据结构多, 如字符串, 散列(hashes), 列表(lists), 集合(sets), 有序集合(sorted sets)与范围查询, bitmaps, hyperloglogs和地理空间(grospatial)索引半径查询.
  • 支持多种语言的接口, C C++, Python, Erlang, R, C#, Java, PHP, Objective-C, Perl, Ruby, Scala, Go, JavaScript

配置安装

点击进去官网

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
wget http://download.redis.io/releases/redis-5.0.3.tar.gz
tar zxvf redis-5.0.3.tar.gz
cd redis-5.0.3
yum -y install gcc tcl
make && make PREFIX=/opt/redis install
# 安装失败
cd deps
make hiredis jemalloc linenoise lua
cd ..
make && make PREFIX=/opt/redis install
# 生成/opt/redis/bin
-rwxr-xr-x. 1 root root 4366576 Jan 31 05:12 redis-benchmark
-rwxr-xr-x. 1 root root 8090008 Jan 31 05:12 redis-check-aof
-rwxr-xr-x. 1 root root 8090008 Jan 31 05:12 redis-check-rdb
-rwxr-xr-x. 1 root root 4801832 Jan 31 05:12 redis-cli
lrwxrwxrwx. 1 root root 12 Jan 31 05:12 redis-sentinel -> redis-server
-rwxr-xr-x. 1 root root 8090008 Jan 31 05:12 redis-server

# 配置环境变量
# redis
export REDIS_HOME=/opt/redis
export PATH=$PATH:$REDIS_HOME/bin

安装redis-server

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
35
36
37
38
39
40
[root@node0 utils]# ./install_server.sh 
Welcome to the redis service installer
This script will help you easily set up a running redis server

Please select the redis port for this instance: [6379]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf]
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log]
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379]
Selected default - /var/lib/redis/6379
Please select the redis executable path [/opt/redis/bin/redis-server]
Selected config:
Port : 6379
Config file : /etc/redis/6379.conf
Log file : /var/log/redis_6379.log
Data dir : /var/lib/redis/6379
Executable : /opt/redis/bin/redis-server
Cli Executable : /opt/redis/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!
[root@node0 utils]# redis-cli
127.0.0.1:6379> help
redis-cli 5.0.3
To get help about Redis commands type:
"help @<group>" to get a list of commands in <group>
"help <command>" for help on <command>
"help <tab>" to get a list of possible help topics
"quit" to exit

To set redis-cli preferences:
":set hints" enable online hints
":set nohints" disable online hints
Set your preferences in ~/.redisclirc

命令

  • help
  • help
  • help set
  • help @string
1
2
3
4
5
6
7
# 查询keys

# 设置多个键的字符串值

# 键不存在设置value值

# 查询键

切换数据库

1
redis-cli -n 1 # 切换到1号数据库
Donate comment here