php-redis知识点汇集

转自:http://my.oschina.net/cniiliuqi/blog/67423

1、Example

$redis->pconnect('127.0.0.1', 6379);
$redis->pconnect('127.0.0.1'); // port 6379 by default - same connection like before.
$redis->pconnect('127.0.0.1', 6379, 2.5); // 2.5 sec timeout and would be another connection than the two before.
$redis->pconnect('127.0.0.1', 6379, 2.5, 'x'); // x is sent as persistent_id and would be another connection the the three before.
$redis->pconnect('/tmp/redis.sock'); // unix domain socket - would be another connection than the four before.

 2、AUTH password http://redis.readthedocs.org/en/latest/connection/auth.html

写道
# 设置密码

redis> CONFIG SET requirepass secret_password # 将密码设置为 secret_password
OK

redis> QUIT # 退出再连接,让新密码对客户端生效

[huangz@mypad]$ redis

redis> PING # 未验证密码,操作被拒绝
(error) ERR operation not permitted

redis> AUTH wrong_password_testing # 尝试输入错误的密码
(error) ERR invalid password

redis> AUTH secret_password # 输入正确的密码
OK

redis> PING # 密码验证成功,可以正常操作命令了
PONG


# 清空密码

redis> CONFIG SET requirepass "" # 通过将密码设为空字符来清空密码
OK

redis> QUIT

$ redis # 重新进入客户端

redis> PING # 执行命令不再需要密码,清空密码操作成功
PONG

3、Redis的PHP字符串实例 http://www.yiibai.com/redis/redis_php.html

<?php
   //Connecting to Redis server on localhost
   $redis = new Redis();
   $redis->connect('127.0.0.1', 6379);
   echo "Connection to server sucessfully";
   //set the data in redis string
   $redis->set("tutorial-name", "Redis tutorial");
   // Get the stored data and print it
   echo "Stored string in redis:: " + jedis.get("tutorial-name");
?>

  

相关推荐