打包下载地址:
链接:https://pan.baidu.com/s/1ymcVPULFCgGXQSIqIDbZgg 提取码:6ha8
1.安装REDIS
下载地址:https://github.com/microsoftarchive/redis/releases
2.安装php扩展
把压缩包中的php_redis.dll放到php/etx目录下,在php.ini中添加extension=php_redis.dll。如找不到vc14版本的可在打包下载地址里面下载。扩展版本参照phpinfo
下载地址:https://windows.php.net/downloads/pecl/snaps/redis/
3.使用
常用命令集redis-cli
keys *,set key value,get key,del key
直连示例:
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$redis->auth('mypasword'); //密码
$redis->select(1);//库必须是int
$redis->set( "testKey" , "Hello Sunar");
echo $redis->get("testKey");
thinkphp示例
use think\cache\driver\Redis;
class Test extends Common
{
public function index()
{
$redis = new Redis();
$data = array(
"code" => 200,
"msg" => "test"
);
$redis->set('JX_TEST', $data); //写入
print_r($redis->get('JX_TEST')); //获取
// $redis->rm('JX_TEST'); //删除
}
}
TP自带的REDIS扩展如下:
/**
* 扩展
*/
//将值插入到列表头部
public function lpush($key,$value){
$this->writeTimes++;
return $this->handler->lPush($key,$value);
}
//通过索引设置列表元素的值
public function lset($key,$index,$value){
$this->writeTimes++;
return $this->handler->lSet($key,$index,$value);
}
//通过索引获取列表中的元素
public function lindex($key,$index){
return $this->handler->lIndex($key,$index);
}
//查询列表
public function lrange($key,$start,$stop){
return $this->handler->lRange($key,$start,$stop);
}
//获取列表长度
public function llen($key){
return $this->handler->lLen($key);
}
//移除列表元素
public function lrem($key,$count,$value){
$this->writeTimes++;
return $this->handler->lRem($key,$count,$value);
}
//获取所有建值
public function keys($keys){
return $this->handler->keys($keys);
}