赞
踩
Redis 连接命令主要是用于连接 redis 服务。
10.117.8.188:6379> AUTH 1245 //没有设置redis密码
(error) ERR Client sent AUTH, but no password is set
10.117.8.188:6379> CONFIG SET requirepass "123456"
OK
10.117.8.188:6379> AUTH 123456
OK
10.117.8.188:6379> ECHO 'miss you'
"miss you"
10.117.8.188:6379> ping //连接正常
PONG
10.117.8.188:6379> ping //连接不正常
Could not connect to Redis at 10.117.8.188:6379: Connection refused
10.117.8.188:6379> QUIT
www@iZ23dvyt70vZ:~ $
10.117.8.188:6379> SELECT 1
OK
10.117.8.188:6379[1]> SELECT 3 //注意 Redis 现在的命令提示符多了个 [1]
OK
10.117.8.188:6379[3]> SELECT 15 //注意 Redis 现在的命令提示符多了个 [3]
OK
public function redisTestAction(){
$redis = new \Redis();
$res = $redis->connect('10.117.8.188',6379);
var_dump($res); // bool(true)
}
public function redisTestAction(){
$redis = new \Redis();
$redis->connect('10.117.8.188',6379);
$res = $redis->auth('123456');
var_dump($res); // 验证失败,bool(false)
}
public function redisTestAction(){
$redis = new \Redis();
$redis->connect('10.117.8.188',6379);
$res = $redis->select('12');
var_dump($res); //切换成功,返回bool(true)
}
public function redisTestAction(){
$redis = new \Redis();
$redis->connect('10.117.8.188',6379);
$res = $redis->close();
var_dump($res); // 断开成功,返回:bool(true)
}
public function redisTestAction(){
$redis = new \Redis();
$redis->connect('10.117.8.188',6379);
$res = $redis->setOption(\Redis::OPT_PREFIX, 'myAppName:');
var_dump($res);//bool(true) 设置键前缀
$res1=$redis->setOption(\Redis::OPT_SERIALIZER,\Redis::SERIALIZER_PHP);
var_dump($res1);//bool(true),设置序列化器
}
public function redisTestAction(){
$redis = new \Redis();
$redis->connect('10.117.8.188',6379);
$redis->setOption(\Redis::OPT_PREFIX, 'myAppName:');
$redis->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_PHP);
$res = $redis->getOption(\Redis::OPT_PREFIX);
var_dump($res); // string(10) "myAppName:"
$res1 = $redis->getOption(\Redis::OPT_SERIALIZER);
var_dump($res1); // int(1)
}
public function redisTestAction(){
$redis = new \Redis();
$redis->connect('10.117.8.188',6379);
$res = $redis->ping();
var_dump($res); // string(5) "+PONG"
}
public function redisTestAction(){
$redis = new \Redis();
$redis->connect('10.117.8.188',6379);
$res = $redis->echo('testmessage');
var_dump($res); // string(11) "testmessage"
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。