Table of Contents
2.windows上安装php redis 扩展
3. Linux上安装php redis扩展
4. 开始使用php_redis
Home php教程 php手册 PHP中redis 的安装和使用(2)

PHP中redis 的安装和使用(2)

Jun 06, 2016 pm 07:47 PM
php redis use Preface Install

1. 前言 redis 的安装ok了。无论是在windows还是Linux上安装。虽然按照过程有些不同,但按照成功了,使用方法还是一样。 我们使用redis 一般不会去独立使用它,就像MySQL,我们也是把它配合PHP,java等服务器语言来使用它。同样,redis 也是一样。 这里,我

1. 前言

redis 的安装ok了。无论是在windows还是Linux上安装。虽然按照过程有些不同,但按照成功了,使用方法还是一样。

我们使用redis 一般不会去独立使用它,就像MySQL,我们也是把它配合PHP,java等服务器语言来使用它。同样,redis 也是一样。

这里,我们是在PHP上使用redis。PHP上用redis 很爽。因为一些方法啊、命名啊,都和原生态的redis 一样。只需要记住这些方法就可在PHP上熟练使用了。


2.windows上安装php redis 扩展

php 官方提供了一个php_redis的扩展。推荐使用这种。

1. 下载windows 版本php对应的php扩展。php_redis.dll 。http://l3.yunpan.cn/lk/sVEUY9ygDJIdD 网盘下载:php_redis扩展。里面有针对5.2和5.3版本的PHP。针对下载

2. 将下载的php_redis.dll 复制到php的扩展目录下 php/etc/php_redis.dll  (注意:php_redis是php版本的,不同的php版本对应不同的php_redis。附件中5.3中有64位的插件,注意,这是针对于php 的64位版本,不是针对redis 64位的版本,所以我们的php如果是5.3的。那么就使用5.3/32/php_redis.dll 就可以了。)

3.修改php的配置文件,加载php_redis.dll :extension=php_redis.dll

4.重启Apache 。打开phpinfo页面。就可以看到已经加载php_redis了。这时候就可以使用redis  了。


3. Linux上安装php redis扩展

windows 安装redis 相对容易一下,下载php_redis.dll 放到php5/ext/目录下,然后修改php.ini即可。

其实linux上更容易

我们在ubuntu 上做。

1. 下载安装

sudo wget http://open.imop.us/pr.tar.gz    
//下载phpredis的扩展    

tar zxvf pr.tar.gz     
//下载完成后,解压。不知道为什么解压成这个目录了:owlient-phpredis-5a07edc/

cd owlient-phpredis-5a07edc/   
//进入解压后的目录

phpize    
//这个phpize是安装php模块的。如果没有phpize,系统会提示
你安装php5-dev: apt-get install php5-dev

./configure

make

sudo make install   
//编译一定要加sudo .否则报错,影响使用。
Copy after login

2. 配置使用
修改php.ini文件(/etc/php5/apache2/php.ini) 

在最底部加上:

extension=redis.so
  
重启apache (sudo /etc/init.d/apache2 restart)
Copy after login


3. cli 方式下的配置

我们有可能在cli 方式下使用php , 也会用到redis 。所以也许要配置

vi /etc/php5/cli/php.ini   
#/etc/php5/cli 是专门用给PHP cli 方式下运行的配置文件目录。所以。加在这。

在最底部加上:

extension=redis.so
  
重启apache (sudo /etc/init.d/apache2 restart)
Copy after login

4. 开始使用php_redis

windows : 首先启动redis 服务,手动启动,自动启动都行。不要关闭。

ubuntu: 开机就自动运行了,不需要手动启动了。

    C:\Users\yi.yang>d:  
      
    D:\>cd redis  
      
    D:\redis>redis-server.exe redis.conf  
    [5556] 26 Nov 14:47:55 * Server started, Redis version 2.4.5  
    [5556] 26 Nov 14:47:55 # Open data file dump.rdb: No such file or directory  
    [5556] 26 Nov 14:47:55 * The server is now ready to accept connections on port 6379  
    [5556] 26 Nov 14:47:56 - 0 clients connected (0 slaves), 1179896 bytes in use  
    [5556] 26 Nov 14:48:01 - 0 clients connected (0 slaves), 1179896 bytes in use  
Copy after login

OK .Redis开始运行。
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP's Purpose: Building Dynamic Websites PHP's Purpose: Building Dynamic Websites Apr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP: Handling Databases and Server-Side Logic PHP: Handling Databases and Server-Side Logic Apr 15, 2025 am 12:15 AM

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

Why Use PHP? Advantages and Benefits Explained Why Use PHP? Advantages and Benefits Explained Apr 16, 2025 am 12:16 AM

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

PHP and Python: A Deep Dive into Their History PHP and Python: A Deep Dive into Their History Apr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP vs. Python: Use Cases and Applications PHP vs. Python: Use Cases and Applications Apr 17, 2025 am 12:23 AM

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

See all articles