国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home php教程 PHP開發(fā) redis installation, configuration, usage and redis php extension installation tutorial

redis installation, configuration, usage and redis php extension installation tutorial

Dec 21, 2016 pm 03:11 PM
redis

redis是一個(gè)內(nèi)存數(shù)據(jù)庫(kù),比memcache支持更豐富的value類型,新浪微博就使用redis來做緩存。

redis的源碼安裝

wget http://download.redis.io/redis-stable.tar.gz
tar -zxvf redis-stable.tar.gz
cd redis-stable
make
make test
make install

make時(shí)可能會(huì)報(bào)如下錯(cuò)誤:

zmalloc.o: In function `zmalloc_used_memory':
/root/redis-stable/src/zmalloc.c:223: undefined reference to `__sync_add_and_fetch_4'
collect2: ld returned 1 exit status
make[1]: *** [redis-server] Error 1
make[1]: Leaving directory `/root/redis-stable/src'
make: *** [all] Error 2

解決辦法:
編輯src/.make-settings里的OPT,改為OPT=-O2 -march=i686。


make test報(bào)錯(cuò):

You need tcl 8.5 or newer in order to run the Redis test
make: *** [test] Error 1

解決辦法安裝tcl

wget http://downloads.sourceforge.net/tcl/tcl8.6.0-src.tar.gz
cd tcl8.6.0/
cd unix &&
./configure --prefix=/usr \
            --mandir=/usr/share/man \
            --without-tzdata \
            $([ $(uname -m) = x86_64 ] && echo --enable-64bit) &&
make &&
sed -e "s@^\(TCL_SRC_DIR='\).*@\1/usr/include'@" \
    -e "/TCL_B/s@='\(-L\)\?.*unix@='\1/usr/lib@" \
    -i tclConfig.sh
make install &&
make install-private-headers &&
ln -v -sf tclsh8.6 /usr/bin/tclsh &&
chmod -v 755 /usr/lib/libtcl8.6.so

redis命令介紹


Redis 由四個(gè)可執(zhí)行文件:redis-benchmark、redis-cli、redis-server、redis-stat 這四個(gè)文件,加上一個(gè)redis.conf就構(gòu)成了整個(gè)redis的最終可用包。它們的作用如下:

redis-server:Redis服務(wù)器的daemon啟動(dòng)程序
redis-cli:Redis命令行操作工具。當(dāng)然,你也可以用telnet根據(jù)其純文本協(xié)議來操作
redis-benchmark:Redis性能測(cè)試工具,測(cè)試Redis在你的系統(tǒng)及你的配置下的讀寫性能
redis-stat:Redis狀態(tài)檢測(cè)工具,可以檢測(cè)Redis當(dāng)前狀態(tài)參數(shù)及延遲狀況
現(xiàn)在就可以啟動(dòng)redis了,redis只有一個(gè)啟動(dòng)參數(shù),就是他的配置文件路徑。

啟動(dòng)redis

復(fù)制源碼包里的redis.conf到/etc

# cd redis-stable
# cp redis.conf /etc/redis.conf

編輯/etc/redis.conf ,修改daemaon no 為daemaon yes ,以守護(hù)進(jìn)程方式啟動(dòng)進(jìn)程。

# redis-server /etc/redis.conf

關(guān)閉redis

# redis-cli shutdown //關(guān)閉所有
關(guān)閉某個(gè)端口上的redis
# redis-cli -p 6397 shutdown //關(guān)閉6397端口的redis

說明:關(guān)閉以后緩存數(shù)據(jù)會(huì)自動(dòng)dump到硬盤上,硬盤地址見redis.conf中的dbfilename dump.rdb


redis配置

注意,默認(rèn)復(fù)制過去的redis.conf文件的daemonize參數(shù)為no,所以redis不會(huì)在后臺(tái)運(yùn)行,這時(shí)要測(cè)試,我們需要重新開一個(gè)終端。修改為yes則為后臺(tái)運(yùn)行redis。另外配置文件中規(guī)定了pid文件,log文件和數(shù)據(jù)文件的地址,如果有需要先修改,默認(rèn)log信息定向到stdout.

下面是redis.conf的主要配置參數(shù)的意義:

daemonize:是否以后臺(tái)daemon方式運(yùn)行
pidfile:pid文件位置
port:監(jiān)聽的端口號(hào)
timeout:請(qǐng)求超時(shí)時(shí)間
loglevel:log信息級(jí)別
logfile:log文件位置
databases:開啟數(shù)據(jù)庫(kù)的數(shù)量
save * *:保存快照的頻率,第一個(gè)*表示多長(zhǎng)時(shí)間,第三個(gè)*表示執(zhí)行多少次寫操作。在一定時(shí)間內(nèi)執(zhí)行一定數(shù)量的寫操作時(shí),自動(dòng)保存快照??稍O(shè)置多個(gè)條件。
rdbcompression:是否使用壓縮
dbfilename:數(shù)據(jù)快照文件名(只是文件名,不包括目錄)
dir:數(shù)據(jù)快照的保存目錄(這個(gè)是目錄)
appendonly:是否開啟appendonlylog,開啟的話每次寫操作會(huì)記一條log,這會(huì)提高數(shù)據(jù)抗風(fēng)險(xiǎn)能力,但影響效率。
appendfsync:appendonlylog如何同步到磁盤(三個(gè)選項(xiàng),分別是每次寫都強(qiáng)制調(diào)用fsync、每秒啟用一次fsync、不調(diào)用fsync等待系統(tǒng)自己同步)
這時(shí)你可以打開一個(gè)終端進(jìn)行測(cè)試了,配置文件中默認(rèn)的監(jiān)聽端口是6379

redis開機(jī)自動(dòng)啟動(dòng)

用這個(gè)腳本管理之前,需要先配置下面的內(nèi)核參數(shù),否則Redis腳本在重啟或停止redis時(shí),將會(huì)報(bào)錯(cuò),并且不能自動(dòng)在停止服務(wù)前同步數(shù)據(jù)到磁盤上:

# vi /etc/sysctl.conf
vm.overcommit_memory = 1

然后應(yīng)用生效:

# sysctl –p

建立redis啟動(dòng)腳本:

# vim /etc/init.d/redis
#!/bin/bash 
# 
# Init file for redis 
# 
# chkconfig: - 80 12 
# description: redis daemon 
# 
# processname: redis 
# config: /etc/redis.conf 
# pidfile: /var/run/redis.pid 
source /etc/init.d/functions 
#BIN="/usr/local/bin" 
BIN="/usr/local/bin" 
CONFIG="/etc/redis.conf" 
PIDFILE="/var/run/redis.pid" 
### Read configuration 
[ -r "$SYSCONFIG" ] && source "$SYSCONFIG" 
RETVAL=0 
prog="redis-server" 
desc="Redis Server" 
start() { 
        if [ -e $PIDFILE ];then 
             echo "$desc already running...." 
             exit 1 
        fi 
        echo -n $"Starting $desc: " 
        daemon $BIN/$prog $CONFIG 
        RETVAL=$? 
        echo 
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog 
        return $RETVAL 
} 
stop() { 
        echo -n $"Stop $desc: " 
        killproc $prog 
        RETVAL=$? 
        echo 
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog $PIDFILE 
        return $RETVAL 
} 
restart() { 
        stop 
        start 
} 
case "$1" in 
  start) 
        start 

  stop) 
        stop 

  restart) 
        restart 

  condrestart) 
        [ -e /var/lock/subsys/$prog ] && restart 
        RETVAL=$? 

  status) 
        status $prog 
        RETVAL=$? 

   *) 
        echo $"Usage: $0 {start|stop|restart|condrestart|status}" 
        RETVAL=1 
esac 
exit $RETVAL

然后增加服務(wù)并開機(jī)自啟動(dòng):

# chmod 755 /etc/init.d/redis 
# chkconfig --add redis 
# chkconfig --level 345 redis on 
# chkconfig --list redis

redis php擴(kuò)展安裝

wget https://github.com/nicolasff/phpredis/zipball/master -O php-redis.zip
unzip php-redis.zip
cd nicolasff-phpredis-2d0f29b/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install

完成后redis.so被安裝到

/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/
vi /usr/local/php/lib/php.ini

添加

extension=redis.so

重啟php-fpm即可。

configure時(shí)可能會(huì)遇到,添加--with-php-config參數(shù)可以解決。

configure: error: Cannot find php-config. Please use --with-php-config=PATH
./configure --with-php-config=/usr/local/php/bin/php-config

更多redis安裝、配置、使用和redis php擴(kuò)展安裝教程相關(guān)文章請(qǐng)關(guān)注PHP中文網(wǎng)!


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

Undress AI Tool

Undress AI Tool

Undress images for free

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.

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)

Hot Topics

PHP Tutorial
1501
276
Recommended Laravel's best expansion packs: 2024 essential tools Recommended Laravel's best expansion packs: 2024 essential tools Apr 30, 2025 pm 02:18 PM

The essential Laravel extension packages for 2024 include: 1. LaravelDebugbar, used to monitor and debug code; 2. LaravelTelescope, providing detailed application monitoring; 3. LaravelHorizon, managing Redis queue tasks. These expansion packs can improve development efficiency and application performance.

Laravel environment construction and basic configuration (Windows/Mac/Linux) Laravel environment construction and basic configuration (Windows/Mac/Linux) Apr 30, 2025 pm 02:27 PM

The steps to build a Laravel environment on different operating systems are as follows: 1.Windows: Use XAMPP to install PHP and Composer, configure environment variables, and install Laravel. 2.Mac: Use Homebrew to install PHP and Composer and install Laravel. 3.Linux: Use Ubuntu to update the system, install PHP and Composer, and install Laravel. The specific commands and paths of each system are different, but the core steps are consistent to ensure the smooth construction of the Laravel development environment.

Redis: A Comparison to Traditional Database Servers Redis: A Comparison to Traditional Database Servers May 07, 2025 am 12:09 AM

Redis is superior to traditional databases in high concurrency and low latency scenarios, but is not suitable for complex queries and transaction processing. 1.Redis uses memory storage, fast read and write speed, suitable for high concurrency and low latency requirements. 2. Traditional databases are based on disk, support complex queries and transaction processing, and have strong data consistency and persistence. 3. Redis is suitable as a supplement or substitute for traditional databases, but it needs to be selected according to specific business needs.

How to limit user resources in Linux? How to configure ulimit? How to limit user resources in Linux? How to configure ulimit? May 29, 2025 pm 11:09 PM

Linux system restricts user resources through the ulimit command to prevent excessive use of resources. 1.ulimit is a built-in shell command that can limit the number of file descriptors (-n), memory size (-v), thread count (-u), etc., which are divided into soft limit (current effective value) and hard limit (maximum upper limit). 2. Use the ulimit command directly for temporary modification, such as ulimit-n2048, but it is only valid for the current session. 3. For permanent effect, you need to modify /etc/security/limits.conf and PAM configuration files, and add sessionrequiredpam_limits.so. 4. The systemd service needs to set Lim in the unit file

Is Redis Primarily a Database? Is Redis Primarily a Database? May 05, 2025 am 12:07 AM

Redis is primarily a database, but it is more than just a database. 1. As a database, Redis supports persistence and is suitable for high-performance needs. 2. As a cache, Redis improves application response speed. 3. As a message broker, Redis supports publish-subscribe mode, suitable for real-time communication.

Redis: Beyond SQL - The NoSQL Perspective Redis: Beyond SQL - The NoSQL Perspective May 08, 2025 am 12:25 AM

Redis goes beyond SQL databases because of its high performance and flexibility. 1) Redis achieves extremely fast read and write speed through memory storage. 2) It supports a variety of data structures, such as lists and collections, suitable for complex data processing. 3) Single-threaded model simplifies development, but high concurrency may become a bottleneck.

Redis: Unveiling Its Purpose and Key Applications Redis: Unveiling Its Purpose and Key Applications May 03, 2025 am 12:11 AM

Redisisanopen-source,in-memorydatastructurestoreusedasadatabase,cache,andmessagebroker,excellinginspeedandversatility.Itiswidelyusedforcaching,real-timeanalytics,sessionmanagement,andleaderboardsduetoitssupportforvariousdatastructuresandfastdataacces

Steps and examples for building a dynamic PHP website with PhpStudy Steps and examples for building a dynamic PHP website with PhpStudy May 16, 2025 pm 07:54 PM

The steps to build a dynamic PHP website using PhpStudy include: 1. Install PhpStudy and start the service; 2. Configure the website root directory and database connection; 3. Write PHP scripts to generate dynamic content; 4. Debug and optimize website performance. Through these steps, you can build a fully functional dynamic PHP website from scratch.

See all articles