后端开发用到php操作redis,在此将安装测试过程中遇到的问题汇总记录下来,以便以后参考!(系统为ubuntu)
1.redis安装
下载地址:http://download.redis.io/releases/
解压安装:
tar -xvf redis-2.8.17.tar.gz
make
sudo make install
为方便使用,在/usr目录下创建redis目录,讲如下几个文件拷贝到/usr/redis/目录下:
/yourdir/redis-2.8.17/redis.conf
/yourdir/redis-2.8.17/src/redis-benchmark
/yourdir/redis-2.8.17/src/redis-server
/yourdir/redis-2.8.17/src/redis-cli
当然,你也可以通过软连接的方式达到方便使用的目的。此外,你也可以将redis-server加入开机启动,此处从略。
2.redis测试
1)先开启redis服务端程序
为方便测试,我们将redis.conf配置文件中的loglevel和logfile的值,修改后如下:
loglevel debug
logfile “/tmp/redis.log”
jay13@ubuntu:/usr/redis$ redis-server redis.conf
2)开启redi客户端,通过客户端向redis数据库中进行增删改查操作。整个操作过程中生成的日志可以到/tmp/redis.log中查看。
以最简单的key操作为例,实例如下:
jay13@ubuntu:/usr/redis$ redis-cli
127.0.0.1:6379> set jay13 jb51.net
OK
127.0.0.1:6379> set jay hello,world
OK
127.0.0.1:6379> get jay
"hello,world"
127.0.0.1:6379> get jay13
"jb51.net"
127.0.0.1:6379> del jay
(integer) 1
127.0.0.1:6379> get jay
(nil)
127.0.0.1:6379> set jay13 www.jb51.net
OK
127.0.0.1:6379> get jay13
"www.jb51.net"
3.安装phpredis扩展
在使用sudo apt-get install php5安装php时,默认是没有安装phpize的,我们安装phpredis时,需要用到phpize,因此,需要先安装phpize。
1)我们通过安装php开发者工具来获取phpize。执行如下命令即可:
sudo apt-get install php5-dev
2)获取phpredis源文件
最新的phpRedis地址:https://github.com/nicolasff/phpredis
按照GitHub上的说明进行如下安装时,
phpize
./configure --enable-redis-igbinary
make && make install
可能会出现如下出错说明:
checking for igbinary includes... configure: error: Cannot find igbinary.h
这个是因为我们没有igbinary扩展,这是phpredis依赖的一个东西。
好吧,怎么安装igbinary呢?
使用apt-get没有无法安装完成,我们通过下载安装文件进行安装。
wget http://pecl.php.net/get/igbinary-1.1.1.tgz
tar -xzvf igbinary-1.1.1.tgz
cd igbinary-1.1.1
phpize
./configure # No need for extra config params
make
make install
安装好igbinary后,可以用如下命令安装phpredis。
phpize
./configure –enable-redis-igbinary
make && make install
至此,安装完成。
我们修改php.ini配置文件,将刚才安装的两个扩展加入到php.ini文件中,加入的语句如下:
extension=igbinary.so
extension=redis.so
重启apache,Done!!!
4.测试php-redis
在网页根目录/var/www/中新建文件test.php,内容如下:
$redis = new Redis();
$redis->connect('127.0.0.1',6379);
$redis->set('Jay13','www.jb51.net');
echo 'Jay13:'.$redis->get('Jay13');
echo '';
echo 'Jay12:'.$redis->get('Jay12');
?>
结果如下图:

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
