問題描述
我是 Redis 的新手...我最近才開始學習 Redisent 來使用 RedisPHP...而且我玩得很開心!但是,我注冊了 Redis to go 服務,并且一直在努力連接以使用該服務..
I am a newbie with Redis...I just recently picked up Redisent to work with Redis in PHP...and I am having tons of fun! However, I signed up for the Redis to go service, and have been beating my head to connect to use the service...
URI 字符串如下:
redis://[用戶名]:[pass]@[server].redistogo.com:[端口]/
redis://[username]:[pass]@[server].redistogo.com:[port]/
Redisent 客戶端只是接收主機名和端口...而我沒有地方輸入用戶名/密碼... :-/我也一直在擺弄 fsockopen() 函數...但沒有分數.
The Redisent client simply takes in the hostname and the port...and there's no place for me to enter the username/password... :-/ I've been fiddling around with the fsockopen() function, too...but no score.
有沒有人嘗試連接到 Redis 以使用 PHP?如果是這樣,任何見解或指示將不勝感激!
Has anyone tried connecting to Redis to go with PHP? If so, any insights or pointers would be greatly appreciated!
注意:我意識到有一個 REST API 可用,但那是用于配置實例,而不是用于 GET/SET 等實際操作.
Note: I realize that there is a REST API available, but that's for provisioning instances, not for the actual operations such as GET/SET,etc.
推薦答案
predis 是首選庫(積極開發 => 2011 年 1 月 6 日) 使用.
predis is the prefered library(active development => 6 Januari 2011) to use.
redis://$x:$y@$z
然后你需要下面的代碼來讓它工作(我測試過):
Then you need the following code to get it working(I tested it):
<?php
require('./Predis.php');
#redis://$x:$y@$z
$redis = new PredisClient('redis://$z');
$redis->auth($y);
$redis->incr('counter');
echo $redis->get('counter');
echo "
";
奇怪的是$x
.根本不需要?
The strange thing is $x
. It is not needed at all?
這篇關于連接到 Redis 以使用 PHP的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!