gpt4 book ai didi

php - 使用 PHP 连接到 Redis

转载 作者:IT王子 更新时间:2023-10-29 06:00:56 24 4
gpt4 key购买 nike

我是 Redis 的新手...我最近刚学会 Redisent在 PHP 中使用 Redis……我玩得很开心!但是,我注册了 Redis to go服务,并一直在敲打我的脑袋以连接使用该服务...

URI字符串如下:

redis://[username]:[pass]@[server].redistogo.com:[port]/

Redisent 客户端只接受主机名和端口...我没有地方可以输入用户名/密码...:-/我也一直在摆弄 fsockopen() 函数。 ..但没有得分。

有没有人尝试连接到 Redis 以使用 PHP?如果是这样,将不胜感激任何见解或指示!

注意:我知道有一个 REST API 可用,但那是用于配置实例,而不是用于 GET/SET 等实际操作。

最佳答案

$db = 1;
$password='password';
$aRedisServers['host']="127.0.0.1";
$aRedisServers['port']= "6379";
$r = new Predis_Client();
$r->connect($aRedisServers['host'], $aRedisServers['port']);
$r->auth($password);
$r->select($db);

$r->set("set","new");
echo $r->get("set");
//output new

关于php - 使用 PHP 连接到 Redis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4918569/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com