Redis 初

 

tcl8.6.1html

$wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
$tar xzvf tcl8.6.1-src.tar.gz  
$cd tcl8.6.1/unix/
$ ./configure
$ make
$ make installredis

 

注意:yum install tcl 更方便数据库

redis-3.0.7
数组

 

$ wget http://download.redis.io/releases/redis-3.0.7.tar.gz
$ tar xzf redis-3.0.7.tar.gz
$ cd redis-3.0.7
$ make
$ make test安全

Run redis-3.0.7服务器


[root@host_0 src]# ./redis-server /root/redis-3.0.7/redis.conf
31143:M 22 Feb 10:18:22.487 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.0.7 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 31143
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-' yii

31143:M 22 Feb 10:18:22.489 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
31143:M 22 Feb 10:18:22.489 # Server started, Redis version 3.0.7
31143:M 22 Feb 10:18:22.489 # 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.
31143:M 22 Feb 10:18:22.489 # 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.
31143:M 22 Feb 10:18:22.489 * The server is now ready to accept connections on port 6379异步

Check redis-3.0.7 Porttcp

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 31143/./redis-serveui

 

Running  redis-3.0.7 Cli

[root@host_0 src]# ./redis-cli
127.0.0.1:6379>

 

Redis安全

在执行命令以前须要密码验证:
检查密码是否设置:
127.0.0.1:6379> CONFIG get requirepass 1) "requirepass" 2) ""

默认状况下,此属性为空,表示没有设置密码,此实例。您能够经过执行如下命令来更改这个属性

127.0.0.1:6379> CONFIG set requirepass "baxk" :要输入密码baxk才能执行命令
OK 127.0.0.1:6379> CONFIG get requirepass 1) "requirepass" 2) "baxk"

链接到了redis后须要使用AUTH命令来身份验证:

的基本语法以下所示:

127.0.0.1:6379> AUTH “baxk” :这样才能成功的执行命令 

语法

127.0.0.1:6379> AUTH "baxk"
OK 127.0.0.1:6379> SET mykey "Test value" OK 127.0.0.1:6379> GET mykey "Test value"
 

 

Redis客户端的基本语法以下

远程服务器上运行命令

要在Redis远程服务器上运行的命令,须要经过同一个客户端redis-cli 链接到服务器

语法
$ redis-cli -h host -p port -a password
例如
下面的示例演示了如何链接到Redis主机:127.0.0.1,端口:6379 上的远程服务器,并加上验证密码为:mypass。

$redis-cli -h 127.0.0.1 -p 6379 -a "mypass"
redis 127.0.0.1:6379>
redis 127.0.0.1:6379> PING

PONG

 

Redis服务器命令基本上都用于管理Redis服务器

 

S.N. 命令和说明
1 BGREWRITEAOF 
异步改写仅追加文件
2 BGSAVE 
异步保存数据集到磁盘
3 CLIENT KILL [ip:port] [ID client-id] 
杀死一个客户端的链接
4 CLIENT LIST 
获取客户端链接到服务器的链接列表
5 CLIENT GETNAME 
获取当前链接的名称
6 CLIENT PAUSE timeout 
中止指定的时间处理来自客户端的命令
7 CLIENT SETNAME connection-name 
设置当前链接名称
8 CLUSTER SLOTS 
获取集群插槽数组节点的映射
9 COMMAND 
获取Redis的命令的详细信息数组
10 COMMAND COUNT 
获得的Redis命令的总数
11 COMMAND GETKEYS 
给予充分的Redis命令提取键
12 BGSAVE 
异步保存数据集到磁盘
13 COMMAND INFO command-name [command-name ...] 
获取具体的Redis命令的详细信息数组
14 CONFIG GET parameter 
获取配置参数的值
15 CONFIG REWRITE 
重写的存储器配置的配置文件
16 CONFIG SET parameter value 
配置参数设置为给定值
17 CONFIG RESETSTAT 
复位信息返回的统计
18 DBSIZE 
返回所选数据库中的键的数目
19 DEBUG OBJECT key 
获取有关的一个关键的调试信息
20 DEBUG SEGFAULT 
使服务器崩溃
21 FLUSHALL 
从全部数据库中删除全部项
22 FLUSHDB 
从当前数据库中删除全部项
23 INFO [section] 
获取有关服务器的信息和统计数据
24 LASTSAVE 
得到最后成功的UNIX时间时间戳保存到磁盘
25 MONITOR 
监听由实时服务器接收到的全部请求
26 ROLE 
返回在复制的状况下实例的角色
27 SAVE 
同步保存数据集到磁盘
28 SHUTDOWN [NOSAVE] [SAVE] 
同步的数据集保存到磁盘,而后关闭服务器
29 SLAVEOF host port 
使服务器为另外一个实例的从站或者促进其做为主
30 SLOWLOG subcommand [argument] 
管理Redis的慢查询日志
31 SYNC 
命令用于复制
32 TIME 返回当前服务器时间
相关文章
相关标签/搜索