03-Redis 操作

1.配置redis环境变量

[root@localhost ~]# echo export PATH=/usr/local/redis/bin/:$PATH >> /etc/profile  
[root@localhost ~]# source /etc/profile

2.redis相关操作,字符串,HASH,集合,有序集合,列表,发布、订阅,等

[root@localhost ~]# redis-cli -h 192.168.2.10 -p 6379    # 连接
192.168.2.10:6379> auth xiaoyi         # 密码认证登录
OK
192.168.2.10:6379> set name linux      # 设置key
OK
192.168.2.10:6379> get name            # 查询
"linux"
192.168.2.10:6379> keys *              # 变量所有keys
1) "name"
192.168.2.10:6379> del name            # 除key

192.168.2.10:6379> select 1            # 切换库,默认是0-15,共16个库

3.redis持久化方式

RDB优点:适合备份,恢复大数据的速度比AOF速度快,快照形式,触发机制

      缺点:fork时有可能停止处理客户端,

AOF优点:追加操作日志文件,AOF文件体积变大时,自动后台进行重写,每秒持久

      缺点:体积大于RDB,速度慢于RDB

4.redis.conf 配置文件详解

 
184 #   save <seconds> <changes>
 185 #
 186 #   Will save the DB if both the given number of seconds and the given
 187 #   number of write operations against the DB occurred.
 188 #
 189 #   In the example below the behaviour will be to save:
 190 #   after 900 sec (15 min) if at least 1 key changed
 191 #   after 300 sec (5 min) if at least 10 keys changed
 192 #   after 60 sec if at least 10000 keys changed
 193 #
 194 #   Note: you can disable saving completely by commenting out all "save" lines.
 195 #
 196 #   It is also possible to remove all the previously configured save
 197 #   points by adding a save directive with a single empty string argument
 198 #   like in the following example:
 199 #
 200 #   save ""
 201 
 202 save 900 1              #  900s,1个key发生改变时,写入磁盘
 203 save 300 10            #  300s,10个key发生改变时,写入磁盘
 204 save 60 10000        #  60s,10000个key发生改变时,写入磁盘

 236 # The filename where to dump the DB
 237 dbfilename dump_6379.rdb   # RDB文件名

 225 rdbcompression yes     #  压缩

 5. redis复制功能,主要占用(内存10G就够了)和(带宽),CPU不太占用

    1.redis使用异步复制

    2.不仅可以有主服务器还可以有从服务器

    3.复制功能不会阻塞主服务器

    4.复制功能尅单纯用于冗余

 

参考文档:

http://doc.redisfans.com/

posted @ 2016-09-02 00:20  sunmmi  阅读(170)  评论(0)    收藏  举报