[root@host b]# telnet 192.168.4.5 11211
Trying 192.168.4.5...
Connected to 192.168.4.5.
Escape character is '^]'.
set name 0 100 3
tom
STORED
get name
VALUE name 0 3
tom
END
replace name 0 200 3
asc
STORED
get name
VALUE name 0 3
asc
END
add set replace delete get
#cd /usr/lcoal/bin
#./php -m (查看php所支持的功能)
#./php -m |grep memcached (查php是否支持memcached)
让php支持memcached
#cd
# tar -zxvf memcahce-2.2.5
# cd memcahce-2.2.5
#/usr/local/php5/bin/phpize
#./configure --with-php-config=/usr/local/php5/bin/php-config --anable-memcache
#make && make install
测试:
浏览器测试:
[root@host ~]# firefox http://192.168.4.5/test.php
test
memcache数据库查看测试效果:
[root@proxe nginx]# telnet 192.168.4.5 11211
Trying 192.168.4.5...
Connected to 192.168.4.5.
Escape character is '^]'.
get key
VALUE key 0 4
test
END
——————————————————————————————————————————————————————————————————————————————————————————————
[root@proxe ~]# cd lnmp_soft
[root@proxe lnmp_soft]# tar -zxf redis-3.0.6.tar.gz
[root@proxe lnmp_soft]# cd redis-3.0.6
[root@proxe redis-3.0.6]# make (没有./configue 是因为老师做的脚本都已经做过之后打包的,所以直接make)
[root@proxe redis-3.0.6]# make install
[root@proxe redis-3.0.6]# cd utils/
[root@proxe utils]# ./install_server.sh (该脚本是提前写好列的,运行后,会复制配置文件,会创建日志文件,开启端口服务,等)
Port : 6379
Config file : /etc/redis/6379.conf
Log file : /var/log/redis_6379.log
Data dir : /var/lib/redis/6379
Executable : /usr/local/bin/redis-server
Cli Executable : /usr/local/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@proxe utils]# redis-cli (支持tab建 上下 还有help帮助)
127.0.0.1:6379> set name tom (默认永久有效)
OK
127.0.0.1:6379> get name
"tom"
127.0.0.1:6379> help set
SET key value [EX seconds] [PX milliseconds] [NX|XX]
summary: Set the string value of a key
since: 1.0.0
group: string
127.0.0.1:6379> set name carry ex 10
OK
127.0.0.1:6379> get name
"carry"
127.0.0.1:6379> get name
"carry"
127.0.0.1:6379> get name
(nil)
127.0.0.1:6379> set name jerry nx (nx新加)
(nil)
127.0.0.1:6379> set test 123 nx
OK
127.0.0.1:6379> set test 111 nx
(nil)
127.0.0.1:6379> set test 111 xx (xx覆盖)
OK
127.0.0.1:6379> get test
"111"
+++++++++++++++++++++++++++++++++++
redis数据库数据保存的位置:(工作中需要备份这里的数据来保存)
cat /var/lib/redis/6379/dump.rdb
+++++++++++++++++++++++++++++++++++
127.0.0.1:6379> set test "hellow the world"
OK
127.0.0.1:6379> get test
"hellow the world"
127.0.0.1:6379> SETRANGE test 12 redinsnh (从零开始算)
(integer) 20
127.0.0.1:6379> get test
"hellow the wredinsnh"
127.0.0.1:6379> SETRANGE test 11 xxx
(integer) 20
127.0.0.1:6379> get test
"hellow the xxxdinsnh"
127.0.0.1:6379> SETRANGE test 11 jjjjjjjjjjjj
(integer) 23
127.0.0.1:6379> get test
"hellow the jjjjjjjjjjjj"
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
set p 101 (每个字符1位,都是显示101.这显示的是字符)
setbit v 0 1 (每个八位,这显示的101是数字)
setbit v 1 0
setbit v 2 1
[root@proxe ~]# /etc/init.d/redis_6379 restart
Stopping ...
Waiting for Redis to shutdown ...
Redis stopped
Starting Redis server...
[root@proxe ~]# /etc/init.d/redis_6379 restart (重启不了。要密码)
Stopping ...
(error) NOAUTH Authentication required.
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
[root@proxe ~]# redis-cli -h
[root@proxe ~]# redis-cli -a 123456
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> set ttt 1235
OK
127.0.0.1:6379> get ttt
"1235"
[root@proxe ~]# redis-cli -a 123456 set abc 123 (非交互式)
OK
[root@proxe ~]# redis-cli -a 123456 get abc
"123"
vim /etc/init.d/redis_6379 (在脚本启动文件中 stop这 加上 -a 123456 密码)
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -a 123456 -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
root@proxe ~]# /etc/init.d/redis_6379 restart
Stopping ...
Waiting for Redis to shutdown ...
Redis stopped
Starting Redis server...