`
alfred_long
  • 浏览: 565537 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Windows下redis 安装与PHP使用

    博客分类:
  • PHP
阅读更多

一、 安装redis及启用服务

(下载地址及安装方式见github  https://github.com/mythz/redis-windows )

1 下载redis客户端

 

http://code.google.com/p/servicestack/wiki/RedisWindowsDownload#Download_32bit_Cygwin_builds_for_Windows

 

2 解压到你所需要的目录中

 

3 创建redis.conf文件

 

 

# Redis configuration file example

# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize no

# When run as a daemon, Redis write a pid file in /var/run/redis.pid by default.
# You can specify a custom pid file location here.
pidfile /var/run/redis.pid

# Accept connections on the specified port, default is 6379
port 6379

# If you want you can bind a single interface, if the bind option is not
# specified all the interfaces will listen for connections.
#
# bind 127.0.0.1

# Close the connection after a client is idle for N seconds (0 to disable)
timeout 300

# Set server verbosity to 'debug'
# it can be one of:
# debug (a lot of information, useful for development/testing)
# notice (moderately verbose, what you want in production probably)
# warning (only very important / critical messages are logged)
loglevel debug

# Specify the log file name. Also 'stdout' can be used to force
# the demon to log on the standard output. Note that if you use standard
# output for logging but daemonize, logs will be sent to /dev/null
logfile stdout

# Set the number of databases. The default database is DB 0, you can select
# a different one on a per-connection basis using SELECT <dbid> where
# dbid is a number between 0 and 'databases'-1
databases 16

################################ SNAPSHOTTING  #################################
#
# Save the DB on disk:
#
#   save <seconds> <changes>
#
#   Will save the DB if both the given number of seconds and the given
#   number of write operations against the DB occurred.
#
#   In the example below the behaviour will be to save:
#   after 900 sec (15 min) if at least 1 key changed
#   after 300 sec (5 min) if at least 10 keys changed
#   after 60 sec if at least 10000 keys changed
save 900 1
save 300 10
save 60 10000

# Compress string objects using LZF when dump .rdb databases?
# For default that's set to 'yes' as it's almost always a win.
# If you want to save some CPU in the saving child set it to 'no' but
# the dataset will likely be bigger if you have compressible values or keys.
rdbcompression yes

# The filename where to dump the DB
dbfilename dump.rdb

# For default save/load DB in/from the working directory
# Note that you must specify a directory not a file name.
dir ./

################################# REPLICATION #################################

# Master-Slave replication. Use slaveof to make a Redis instance a copy of
# another Redis server. Note that the configuration is local to the slave
# so for example it is possible to configure the slave to save the DB with a
# different interval, or to listen to another port, and so on.
#
# slaveof <masterip> <masterport>

# If the master is password protected (using the "requirepass" configuration
# directive below) it is possible to tell the slave to authenticate before
# starting the replication synchronization process, otherwise the master will
# refuse the slave request.
#
# masterauth <master-password>

################################## SECURITY ###################################

# Require clients to issue AUTH <PASSWORD> before processing any other
# commands.  This might be useful in environments in which you do not trust
# others with access to the host running redis-server.
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
#
# requirepass foobared

################################### LIMITS ####################################

# Set the max number of connected clients at the same time. By default there
# is no limit, and it's up to the number of file descriptors the Redis process
# is able to open. The special value '0' means no limts.
# Once the limit is reached Redis will close all the new connections sending
# an error 'max number of clients reached'.
#
# maxclients 128

# Don't use more memory than the specified amount of bytes.
# When the memory limit is reached Redis will try to remove keys with an
# EXPIRE set. It will try to start freeing keys that are going to expire
# in little time and preserve keys with a longer time to live.
# Redis will also try to remove objects from free lists if possible.
#
# If all this fails, Redis will start to reply with errors to commands
# that will use more memory, like SET, LPUSH, and so on, and will continue
# to reply to most read-only commands like GET.
#
# WARNING: maxmemory can be a good idea mainly if you want to use Redis as a
# 'state' server or cache, not as a real DB. When Redis is used as a real
# database the memory usage will grow over the weeks, it will be obvious if
# it is going to use too much memory in the long run, and you'll have the time
# to upgrade. With maxmemory after the limit is reached you'll start to get
# errors for write operations, and this may even lead to DB inconsistency.
#
# maxmemory <bytes>

############################## APPEND ONLY MODE ###############################

# By default Redis asynchronously dumps the dataset on disk. If you can live
# with the idea that the latest records will be lost if something like a crash
# happens this is the preferred way to run Redis. If instead you care a lot
# about your data and don't want to that a single record can get lost you should
# enable the append only mode: when this mode is enabled Redis will append
# every write operation received in the file appendonly.log. This file will
# be read on startup in order to rebuild the full dataset in memory.
#
# Note that you can have both the async dumps and the append only file if you
# like (you have to comment the "save" statements above to disable the dumps).
# Still if append only mode is enabled Redis will load the data from the
# log file at startup ignoring the dump.rdb file.
#
# The name of the append only file is "appendonly.log"
#
# IMPORTANT: Check the BGREWRITEAOF to check how to rewrite the append
# log file in background when it gets too big.

appendonly no

# The fsync() call tells the Operating System to actually write data on disk
# instead to wait for more data in the output buffer. Some OS will really flush
# data on disk, some other OS will just try to do it ASAP.
#
# Redis supports three different modes:
#
# no: don't fsync, just let the OS flush the data when it wants. Faster.
# always: fsync after every write to the append only log . Slow, Safest.
# everysec: fsync only if one second passed since the last fsync. Compromise.
#
# The default is "always" that's the safer of the options. It's up to you to
# understand if you can relax this to "everysec" that will fsync every second
# or to "no" that will let the operating system flush the output buffer when
# it want, for better performances (but if you can live with the idea of
# some data loss consider the default persistence mode that's snapshotting).

appendfsync always
# appendfsync everysec
# appendfsync no

############################### ADVANCED CONFIG ###############################

# Glue small output buffers together in order to send small replies in a
# single TCP packet. Uses a bit more CPU but most of the times it is a win
# in terms of number of queries per second. Use 'yes' if unsure.
glueoutputbuf yes

# Use object sharing. Can save a lot of memory if you have many common
# string in your dataset, but performs lookups against the shared objects
# pool so it uses more CPU and can be a bit slower. Usually it's a good
# idea.
#
# When object sharing is enabled (shareobjects yes) you can use
# shareobjectspoolsize to control the size of the pool used in order to try
# object sharing. A bigger pool size will lead to better sharing capabilities.
# In general you want this value to be at least the double of the number of
# very common strings you have in your dataset.
#
# WARNING: object sharing is experimental, don't enable this feature
# in production before of Redis 1.0-stable. Still please try this feature in
# your development environment so that we can test it better.
# shareobjects no
# shareobjectspoolsize 1024

 

 4 在命令行下启动服务

    

启动成功后显示(此窗口会一直滚动,不要关闭,否则redis就停止了)

 

5 设置redis服务客户端

 

之后会显示

 

6 测试

 

window下安装成功

 

二、PHP中使用

1 添加phpredis扩展

 首先,查看所用php编译版本V6/V9 在phpinfo()中查看

 

 

2 下载扩展 地址:https://github.com/nicolasff/phpredis/downloads(注意所支持的php版本)

 

3 将下载的php_redis.dll放在php扩展目录中(ext),并修改配置文件php.ini(添加extension=php_redis.dll)

 

4 重新启动服务,查看phpinfo(),下面表示成功;

 

 

5 用PHP测试

 

$redis = new Redis();
$redis->connect("192.168.138.2","6379");  //php客户端设置的ip及端口
//存储一个 值
$redis->set("say","Hello World");
echo $redis->get("say");     //应输出Hello World

//存储多个值
$array = array('first_key'=>'first_val',
          'second_key'=>'second_val',
          'third_key'=>'third_val');
$array_get = array('first_key','second_key','third_key');
$redis->mset($array);
var_dump($redis->mget($array_get));


 

 

linux下待实践无误以后奉上

  • 大小: 8.1 KB
  • 大小: 92.2 KB
  • 大小: 5.6 KB
  • 大小: 1.6 KB
  • 大小: 11 KB
  • 大小: 7 KB
  • 大小: 10.6 KB
分享到:
评论

相关推荐

    windows下redis PHP5.5扩展

    通过以上步骤和理解,开发者可以在Windows环境下顺利地使用PHP 5.5与Redis进行数据交互,提高Web应用程序的性能和响应速度。同时,了解并熟练运用`php_redis`扩展的各种功能,能够更好地利用Redis的强大功能。

    PHP8的redis扩展安装for Windows

    通过以上步骤,你应该能够在Windows下的PHP8环境中成功安装和使用Redis扩展。这将极大地提升你的Web应用程序的性能,尤其是在处理高并发和数据缓存时。在实际应用中,根据项目需求,你可能还需要考虑其他因素,如...

    redis for Windows 7.0.7 使用cygwin编译

    在Windows 7.0.7系统中使用Cygwin编译Redis 7.0.7版本,首先需要安装Cygwin,并确保在安装时选择了编译Redis所需的依赖包,如gcc、make、autoconf、automake等。 编译Redis的步骤大致如下: 1. 下载Redis源代码:...

    windows,php8.2,redis 扩展

    windows10 ,php8.2, redis 扩展

    redis安装使用文档

    总的来说,Redis的安装与使用并不复杂,只需按照步骤进行即可。配合PHP的Redis扩展,可以在Web应用中轻松实现高效的数据缓存和处理。通过不断的实践和学习,你将能够更好地掌握Redis的各种功能和应用场景。

    windows下php5.3 redis扩展 php_redis.dll

    在Windows环境下,PHP 5.3的Redis扩展是开发者与Redis数据库进行交互的重要工具。Redis是一种高性能的键值数据存储系统,广泛应用于缓存、消息队列等场景。本文将详细解析如何在Windows上安装并配置PHP 5.3的Redis...

    Windows系统redis安装方法和PHP各个版本的redis扩展(附带一键启动redis脚本)

    在本文中,我们将深入探讨如何在Windows操作系统上安装Redis,并为不同版本的PHP(从PHP 5.3到PHP 7.0)安装相应的Redis扩展。Redis是一个高性能的键值存储系统,常用于缓存、数据库和消息中间件。而PHP的Redis扩展...

    Windows 下redis的的扩展

    在Windows环境下,Redis的使用可能相对复杂,但通过一些扩展工具和配置,我们可以轻松地将Redis集成到PHP环境中。本文将详细介绍如何在Windows上安装Redis,以及如何利用php5.5版本的Redis扩展和rediswatcher工具...

    Windows系统redis安装方法和各个PHP版本dll文件

    下面将详细介绍Windows系统下安装Redis以及为不同PHP版本安装Redis扩展的步骤。 首先,我们来看如何在Windows上安装Redis。你可以从Redis的官方网站下载适用于Windows的预编译版本。通常,这会是一个.zip文件,例如...

    window下 php5 安装redis 及安装php-redis扩展 (亲测有用)

    phpredis是个人觉得最好的一个php-redis客户端,因为其提供的function与redis的命令基本一致,降低的了学习成本,...1. windows下redis的客户端,可直接安装redis; 2. php5.5 的redis扩展(64位和32位的dll文件);

    windows下安装Redis并部署成服务

    在Windows环境下安装Redis并将其部署为服务是一项常见的任务,尤其对于需要使用Redis作为持久化缓存或消息队列的PHP开发者来说。以下是详细的步骤和注意事项: 1. **下载Redis** Redis官方提供了针对不同操作系统...

    php使用redis在windows下配置方法

    在windows下安装php的redis扩展非常简单,下载一个.dll扩展包放到php的ext目录下,在php.ini里边添加一行配置就可以了. http://ishare.iask.sina.com.cn/f/23044929.html?from=like 下载 php_redis.dll 文件解压并放到...

    亲测能用,windows下redis-2.45服务端及php5.2配置dll

    本文将详细介绍如何在Windows环境下配置Redis服务器,并与PHP 5.2进行集成。 首先,我们来看看标题提到的“redis-2.45”版本。这是一个较早的Redis版本,发布于2012年。尽管现在Redis已经更新到更高级的版本,如6.x...

    phpRedis拓展和redis安装.zip

    描述中说“安装redis启动后就可以使用redis”,这意味着一旦Redis服务器运行起来,就可以在PHP中通过phpRedis扩展来访问Redis实例。在PHP代码中,首先需要调用`extension_loaded('redis')`检查redis扩展是否已经加载...

    php_redis for windows

    在Windows环境下开发和运行PHP应用程序时,常常需要与Redis这种高性能的键值存储系统进行交互。`php_redis`扩展是PHP语言与Redis通信的关键桥梁,它使得PHP开发者能够充分利用Redis的数据结构服务器特性。本知识点将...

    windows下php5.3 v9 redis扩展 php_redis.dll

    标题中的“windows下php5.3 v9 redis扩展 php_redis.dll”指的是在Windows操作系统环境下,针对PHP 5.3版本的v9构建的Redis扩展,这个扩展的主要功能是让PHP能够与Redis内存数据存储系统进行交互。Redis是一个开源的...

    windows安装redis和php<=7.2的redis所有扩展(附带一键启动redis脚本!)

    里面包含windows安装最新版redis和php-redis各个版本的扩展(php5.3~7.2)详情点击:https://blog.csdn.net/sinat_15955423/article/details/78920489

    redis安装包以及phpredis扩展包-windows

    在Windows环境中安装Redis,需要考虑系统架构(32位或64位),同时为了在PHP中使用Redis,还需要安装对应的PHP Redis扩展。本资源包含Redis 3.0.504 64位的安装包以及适用于Redis 3.0的PHP Redis扩展,适用于32位和...

    php5.6下的redis扩展(redis/php_redis.dll/php_igbinary.dll)windows环境

    在Windows环境下配置PHP以使用Redis扩展,可以显著提升Web应用的性能。本资源合集专注于PHP 5.6版本在Windows NTX操作系统上的配置,提供了必要的组件来实现这一目标。 首先,Redis-x64-2.8.2104.zip是Redis服务器...

Global site tag (gtag.js) - Google Analytics