作者:蓝眼泪
redis 和memcached类似、 yum install redis redis-server redis-cli redis-cli shutdown pkill -9 redis
wget redis3.2 tar -zxvf redis3.2 cd redis3.2 yum install gcc gcc-c++ make echo $? make prefix=/usr/local/redis install mkdir /usr/local/redis/etc cp -a redis.conf /usr/local/redis/etc/ vim /usr/local/redis/etc/redis.conf daemonize yes ln -s /usr/local/redis/bin/* /usr/local/bin/ /usr/local/redis/bin/redis-server /usr/local/redis/bin/redis-cli redis-server /usr/local/redis/etc/redis.conf
1 string类型及操作
set name=wenjl get name setnx name=wenjl mset age 18 sex man mget name age sex incrby age 5 del
2 hash结构
hmset a1 name zhangs age 10 sex man hmset a2 name lisi age 18 sex man hmget a1 name age sex hmget a2 name age sex push pop smtp pop push pull
3 list链表结构
lpush zhangsan zhangsan lpush zhangsan 40 lpush zhangsan man lrange zhangsan 0 -1 lpush&lpop lpush&rpop rpush&lpop rpush&rpop
4 set集合类型
sadd mset 1 2 3 4 5 6 smembers mset srem mset 2 4 6 smembers mset scard mset spop mset smembers mset sdiff mset1 mset2 sdiff mset2 mset1 sinter mset1 mset2 sunion mset1 mset2 sadd mset1 1 2 3 4 sadd mset2 3 4 5 6
5 zset有序集合类型
zadd zset 2 zhangsan 1 lisi 1 wangwu zrange zset 0 -1 withscores zcard zset
keys *set exists zset select 0 move mset 1 select 1 keys * type mset dbsize save info config get * flushdb flushall
1 密码保护
vim /usr/local/redis/etc/redis.conf requirepass 123456 pkill redis redis-cli -a 123456 ps -aux|grep redis find / -name redis.conf vim /etc/redis.conf redis-cli -a 123456 redis-cli auth 123456 set name liul
2 主从同步
scp redis3.2 root@192.168.88.20:/root vim /usr/local/redis/etc/redis.conf daemonize yes slaveof 192.168.88.10 6379 masterauth 123456
3 1 数据持久化
dump.rdb mkdir /usr/local/redis/datadir vim /etc/redis.conf vim /usr/local/redis/etc/redis.conf dir /usr/local/redis/datadir/
3.2 另一种数据持久化 append-only file 简称aof
vim /usr/local/redis/etc/redis.conf appendonly yes appendsync everysec cd /usr/local/redis/datadir/ ls cat appendonly.aof
unzip *.zip cd redis-mysql ls yum -y install * #搭建lnmp环境 vim /etc/nginx/nginx.conf vim /etc/nginx/conf.d/default.conf vim /etc/php-fpm.d/www.conf user nginx group nginx service php-fpm start mysqladmin -uroot passwd 123456 mysql -uroot -p123456 mkdir /www service mysqld start make make prefix=/usr/local/redis install cp redis.conf /usr/local/redis/ cd /usr/local/redis/ ls unzip phpredis-master.zip cd phpredis-master ls phpize ./configure --with-php-config=/usr/bin/php-config make && make install vim /etc/php.ini extension=redis.so service php-fpm restart
mysql -uroot -p123456 create database mytest; use mytest; create table test (id int,name char(20)); insert into test values (1,'a1'),(2,'a2'),(3,'a3'),(4,'a4'),(5,'a5'); select * from test; vim /etc/redis.conf daemonize yes cp -a redis-mysql.php /www/redis.php