2023-05-12 开启多语言插件支持……

Redis以及Redis的php扩展安装无错版

Linux 苏 demo 2680℃ 0评论

安装Redis

下载最新的

官网:http://redis.io/  或者  http://code.google.com/p/redis/downloads/list

第一步:下载安装编译

#wget http://redis.googlecode.com/files/redis-2.4.4.tar.gz
#tar
zxvf redis-2.4.4.tar.gz
#cd redis-2.4.4
#make
#make install
#cp redis.conf  /etc/

第二步:修改配置

#vi /etc/redis.conf
配置见附录

第三步:启动进程

#redis-server /etc/redis.conf

查看进程有没有成功启动

#ps -ef | grep redis
测试输入一个键值
#redis-cli set test “123456”
获取键值
#redis-cli get test
1

关闭redis
# redis-cli shutdown      //关闭所有
关闭某个端口上的redis
# redis-cli -p 6397 shutdown  //关闭6397端口的redis

说明:关闭以后缓存数据会自动dump到硬盘上,硬盘地址见redis.conf中的dbfilename  dump.rdb

 

PHP扩展

http://code.google.com/p/php-redis/

附录:无错配置
下面是本人配置的全文件
  1. # Redis configuration file example
  2. # Note on units: when memory size is needed, it is possible to specifiy
  3. # it in the usual form of 1k 5GB 4M and so forth:
  4. #
  5. # 1k => 1000 bytes
  6. # 1kb => 1024 bytes
  7. # 1m => 1000000 bytes
  8. # 1mb => 1024*1024 bytes
  9. # 1g => 1000000000 bytes
  10. # 1gb => 1024*1024*1024 bytes
  11. #
  12. # units are case insensitive so 1GB 1Gb 1gB are all the same.
  13. # By default Redis does not run as a daemon. Use ‘yes’ if you need it.
  14. # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
  15. daemonize yes
  16. # When running daemonized, Redis writes a pid file in /var/run/redis.pid by
  17. # default. You can specify a custom pid file location here.
  18. pidfile /var/run/redis.pid
  19. # Accept connections on the specified port, default is 6379.
  20. # If port 0 is specified Redis will not listen on a TCP socket.
  21. port 6379
  22. # If you want you can bind a single interface, if the bind option is not
  23. # specified all the interfaces will listen for incoming connections.
  24. #
  25.  bind 127.0.0.1
  26. # Specify the path for the unix socket that will be used to listen for
  27. # incoming connections. There is no default, so Redis will not listen
  28. # on a unix socket when not specified.
  29. #
  30. # unixsocket /tmp/redis.sock
  31. # unixsocketperm 755
  32. # Close the connection after a client is idle for N seconds (0 to disable)
  33. timeout 600
  34. # Set server verbosity to ‘debug’
  35. # it can be one of:
  36. # debug (a lot of information, useful for development/testing)
  37. # verbose (many rarely useful info, but not a mess like the debug level)
  38. # notice (moderately verbose, what you want in production probably)
  39. # warning (only very important / critical messages are logged)
  40. loglevel verbose
  41. # Specify the log file name. Also ‘stdout’ can be used to force
  42. # Redis to log on the standard output. Note that if you use standard
  43. # output for logging but daemonize, logs will be sent to /dev/null
  44. logfile stdout
  45. # To enable logging to the system logger, just set ‘syslog-enabled’ to yes,
  46. # and optionally update the other syslog parameters to suit your needs.
  47. # syslog-enabled no
  48. # Specify the syslog identity.
  49. # syslog-ident redis
  50. # Specify the syslog facility.  Must be USER or between LOCAL0-LOCAL7.
  51. # syslog-facility local0
  52. # Set the number of databases. The default database is DB 0, you can select
  53. # a different one on a per-connection basis using SELECT <dbid> where
  54. # dbid is a number between 0 and ‘databases’-1
  55. databases 16
  56. ################################ SNAPSHOTTING  #################################
  57. #
  58. # Save the DB on disk:
  59. #
  60. #   save <seconds> <changes>
  61. #
  62. #   Will save the DB if both the given number of seconds and the given
  63. #   number of write operations against the DB occurred.
  64. #
  65. #   In the example below the behaviour will be to save:
  66. #   after 900 sec (15 min) if at least 1 key changed
  67. #   after 300 sec (5 min) if at least 10 keys changed
  68. #   after 60 sec if at least 10000 keys changed
  69. #
  70. #   Note: you can disable saving at all commenting all the “save” lines.
  71. save 900 1
  72. save 300 10
  73. save 60 10000
  74. # Compress string objects using LZF when dump .rdb databases?
  75. # For default that’s set to ‘yes’ as it’s almost always a win.
  76. # If you want to save some CPU in the saving child set it to ‘no’ but
  77. # the dataset will likely be bigger if you have compressible values or keys.
  78. rdbcompression yes
  79. # The filename where to dump the DB
  80. dbfilename dump.rdb
  81. # The working directory.
  82. #
  83. # The DB will be written inside this directory, with the filename specified
  84. # above using the ‘dbfilename’ configuration directive.
  85. #
  86. # Also the Append Only File will be created inside this directory.
  87. #
  88. # Note that you must specify a directory here, not a file name.
  89. dir /usr/local/redis-2.4.4
  1. ################################# REPLICATION #################################
  2. # Master-Slave replication. Use slaveof to make a Redis instance a copy of
  3. # another Redis server. Note that the configuration is local to the slave
  4. # so for example it is possible to configure the slave to save the DB with a
  5. # different interval, or to listen to another port, and so on.
  6. #
  7. # slaveof <masterip> <masterport>
  8. # If the master is password protected (using the “requirepass” configuration
  9. # directive below) it is possible to tell the slave to authenticate before
  10. # starting the replication synchronization process, otherwise the master will
  11. # refuse the slave request.
  12. #
  13. # masterauth <master-password>
  14. # When a slave lost the connection with the master, or when the replication
  15. # is still in progress, the slave can act in two different ways:
  16. #
  17. # 1) if slave-serve-stale-data is set to ‘yes’ (the default) the slave will
  18. #    still reply to client requests, possibly with out of data data, or the
  19. #    data set may just be empty if this is the first synchronization.
  20. #
  21. # 2) if slave-serve-stale data is set to ‘no’ the slave will reply with
  22. #    an error “SYNC with master in progress” to all the kind of commands
  23. #    but to INFO and SLAVEOF.
  24. #
  25. slave-serve-stale-data yes
  26. ################################## SECURITY ###################################
  27. # Require clients to issue AUTH <PASSWORD> before processing any other
  28. # commands.  This might be useful in environments in which you do not trust
  29. # others with access to the host running redis-server.
  30. #
  31. # This should stay commented out for backward compatibility and because most
  32. # people do not need auth (e.g. they run their own servers).
  33. #
  34. # Warning: since Redis is pretty fast an outside user can try up to
  35. # 150k passwords per second against a good box. This means that you should
  36. # use a very strong password otherwise it will be very easy to break.
  37. #
  38. # requirepass foobared
  39. # Command renaming.
  40. #
  41. # It is possilbe to change the name of dangerous commands in a shared
  42. # environment. For instance the CONFIG command may be renamed into something
  43. # of hard to guess so that it will be still available for internal-use
  44. # tools but not available for general clients.
  45. #
  46. # Example:
  47. #
  48. # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
  49. #
  50. # It is also possilbe to completely kill a command renaming it into
  51. # an empty string:
  52. #
  53. # rename-command CONFIG “”
  54. ################################### LIMITS ####################################
  55. # Set the max number of connected clients at the same time. By default there
  56. # is no limit, and it’s up to the number of file descriptors the Redis process
  57. # is able to open. The special value ‘0’ means no limits.
  58. # Once the limit is reached Redis will close all the new connections sending
  59. # an error ‘max number of clients reached’.
  60. #
  61. # maxclients 128
  62. # Don’t use more memory than the specified amount of bytes.
  63. # When the memory limit is reached Redis will try to remove keys with an
  64. # EXPIRE set. It will try to start freeing keys that are going to expire
  65. # in little time and preserve keys with a longer time to live.
  66. # Redis will also try to remove objects from free lists if possible.
  67. #
  68. # If all this fails, Redis will start to reply with errors to commands
  69. # that will use more memory, like SET, LPUSH, and so on, and will continue
  70. # to reply to most read-only commands like GET.
  71. #
  72. # WARNING: maxmemory can be a good idea mainly if you want to use Redis as a
  73. # ‘state’ server or cache, not as a real DB. When Redis is used as a real
  74. # database the memory usage will grow over the weeks, it will be obvious if
  75. # it is going to use too much memory in the long run, and you’ll have the time
  76. # to upgrade. With maxmemory after the limit is reached you’ll start to get
  77. # errors for write operations, and this may even lead to DB inconsistency.
  78. #
  79. # maxmemory <bytes>
  80. # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
  81. # is reached? You can select among five behavior:
  82. #
  83. # volatile-lru -> remove the key with an expire set using an LRU algorithm
  84. # allkeys-lru -> remove any key accordingly to the LRU algorithm
  85. # volatile-random -> remove a random key with an expire set
  86. # allkeys->random -> remove a random key, any key
  87. # volatile-ttl -> remove the key with the nearest expire time (minor TTL)
  88. # noeviction -> don’t expire at all, just return an error on write operations
  89. #
  90. # Note: with all the kind of policies, Redis will return an error on write
  91. #       operations, when there are not suitable keys for eviction.
  92. #
  93. #       At the date of writing this commands are: set setnx setex append
  94. #       incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd
  95. #       sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby
  96. #       zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby
  97. #       getset mset msetnx exec sort
  98. #
  99. # The default is:
  100. #
  101. # maxmemory-policy volatile-lru
  102. # LRU and minimal TTL algorithms are not precise algorithms but approximated
  103. # algorithms (in order to save memory), so you can select as well the sample
  104. # size to check. For instance for default Redis will check three keys and
  105. # pick the one that was used less recently, you can change the sample size
  106. # using the following configuration directive.
  107. #
  108. # maxmemory-samples 3
  109. ############################## APPEND ONLY MODE ###############################
  110. # By default Redis asynchronously dumps the dataset on disk. If you can live
  111. # with the idea that the latest records will be lost if something like a crash
  112. # happens this is the preferred way to run Redis. If instead you care a lot
  113. # about your data and don’t want to that a single record can get lost you should
  114. # enable the append only mode: when this mode is enabled Redis will append
  115. # every write operation received in the file appendonly.aof. This file will
  116. # be read on startup in order to rebuild the full dataset in memory.
  117. #
  118. # Note that you can have both the async dumps and the append only file if you
  119. # like (you have to comment the “save” statements above to disable the dumps).
  120. # Still if append only mode is enabled Redis will load the data from the
  121. # log file at startup ignoring the dump.rdb file.
  122. #
  123. # IMPORTANT: Check the BGREWRITEAOF to check how to rewrite the append
  124. # log file in background when it gets too big.
  125. appendonly yes
  126. # The name of the append only file (default: “appendonly.aof”)
  127.  appendfilename appendonly.aof
  128. # The fsync() call tells the Operating System to actually write data on disk
  129. # instead to wait for more data in the output buffer. Some OS will really flush
  130. # data on disk, some other OS will just try to do it ASAP.
  131. #
  132. # Redis supports three different modes:
  133. #
  134. # no: don’t fsync, just let the OS flush the data when it wants. Faster.
  135. # always: fsync after every write to the append only log . Slow, Safest.
  136. # everysec: fsync only if one second passed since the last fsync. Compromise.
  137. #
  138. # The default is “everysec” that’s usually the right compromise between
  139. # speed and data safety. It’s up to you to understand if you can relax this to
  140. # “no” that will will let the operating system flush the output buffer when
  141. # it wants, for better performances (but if you can live with the idea of
  142. # some data loss consider the default persistence mode that’s snapshotting),
  143. # or on the contrary, use “always” that’s very slow but a bit safer than
  144. # everysec.
  145. #
  146. # If unsure, use “everysec”.
  147. # appendfsync always
  148. appendfsync everysec
  149. # appendfsync no
  150. # When the AOF fsync policy is set to always or everysec, and a background
  151. # saving process (a background save or AOF log background rewriting) is
  152. # performing a lot of I/O against the disk, in some Linux configurations
  153. # Redis may block too long on the fsync() call. Note that there is no fix for
  154. # this currently, as even performing fsync in a different thread will block
  155. # our synchronous write(2) call.
  156. #
  157. # In order to mitigate this problem it’s possible to use the following option
  158. # that will prevent fsync() from being called in the main process while a
  159. # BGSAVE or BGREWRITEAOF is in progress.
  160. #
  161. # This means that while another child is saving the durability of Redis is
  162. # the same as “appendfsync none”, that in pratical terms means that it is
  163. # possible to lost up to 30 seconds of log in the worst scenario (with the
  164. # default Linux settings).
  165. #
  166. # If you have latency problems turn this to “yes”. Otherwise leave it as
  167. # “no” that is the safest pick from the point of view of durability.
  168. no-appendfsync-on-rewrite no
  169. # Automatic rewrite of the append only file.
  170. # Redis is able to automatically rewrite the log file implicitly calling
  171. # BGREWRITEAOF when the AOF log size will growth by the specified percentage.
  172. #
  173. # This is how it works: Redis remembers the size of the AOF file after the
  174. # latest rewrite (or if no rewrite happened since the restart, the size of
  175. # the AOF at startup is used).
  176. #
  177. # This base size is compared to the current size. If the current size is
  178. # bigger than the specified percentage, the rewrite is triggered. Also
  179. # you need to specify a minimal size for the AOF file to be rewritten, this
  180. # is useful to avoid rewriting the AOF file even if the percentage increase
  181. # is reached but it is still pretty small.
  182. #
  183. # Specify a precentage of zero in order to disable the automatic AOF
  184. # rewrite feature.
  185. auto-aof-rewrite-percentage 100
  186. auto-aof-rewrite-min-size 64mb
  187. ################################## SLOW LOG ###################################
  188. # The Redis Slow Log is a system to log queries that exceeded a specified
  189. # execution time. The execution time does not include the I/O operations
  190. # like talking with the client, sending the reply and so forth,
  191. # but just the time needed to actually execute the command (this is the only
  192. # stage of command execution where the thread is blocked and can not serve
  193. # other requests in the meantime).
  194. #
  195. # You can configure the slow log with two parameters: one tells Redis
  196. # what is the execution time, in microseconds, to exceed in order for the
  197. # command to get logged, and the other parameter is the length of the
  198. # slow log. When a new command is logged the oldest one is removed from the
  199. # queue of logged commands.
  200. # The following time is expressed in microseconds, so 1000000 is equivalent
  201. # to one second. Note that a negative number disables the slow log, while
  202. # a value of zero forces the logging of every command.
  203. slowlog-log-slower-than 10000
  204. # There is no limit to this length. Just be aware that it will consume memory.
  205. # You can reclaim memory used by the slow log with SLOWLOG RESET.
  206. slowlog-max-len 1024
  207. ################################ VIRTUAL MEMORY ###############################
  208. ### WARNING! Virtual Memory is deprecated in Redis 2.4
  209. ### The use of Virtual Memory is strongly discouraged.
  210. # Virtual Memory allows Redis to work with datasets bigger than the actual
  211. # amount of RAM needed to hold the whole dataset in memory.
  212. # In order to do so very used keys are taken in memory while the other keys
  213. # are swapped into a swap file, similarly to what operating systems do
  214. # with memory pages.
  215. #
  216. # To enable VM just set ‘vm-enabled’ to yes, and set the following three
  217. # VM parameters accordingly to your needs.
  218. vm-enabled no
  219.  #vm-enabled yes
  220. # This is the path of the Redis swap file. As you can guess, swap files
  221. # can’t be shared by different Redis instances, so make sure to use a swap
  222. # file for every redis process you are running. Redis will complain if the
  223. # swap file is already in use.
  224. #
  225. # The best kind of storage for the Redis swap file (that’s accessed at random)
  226. # is a Solid State Disk (SSD).
  227. #
  228. # *** WARNING *** if you are using a shared hosting the default of putting
  229. # the swap file under /tmp is not secure. Create a dir with access granted
  230. # only to Redis user and configure Redis to create the swap file there.
  231. vm-swap-file /tmp/redis.swap
  232. # vm-max-memory configures the VM to use at max the specified amount of
  233. # RAM. Everything that deos not fit will be swapped on disk *if* possible, that
  234. # is, if there is still enough contiguous space in the swap file.
  235. #
  236. # With vm-max-memory 0 the system will swap everything it can. Not a good
  237. # default, just specify the max amount of RAM you can in bytes, but it’s
  238. # better to leave some margin. For instance specify an amount of RAM
  239. # that’s more or less between 60 and 80% of your free RAM.
  240. vm-max-memory 0
  241. # Redis swap files is split into pages. An object can be saved using multiple
  242. # contiguous pages, but pages can’t be shared between different objects.
  243. # So if your page is too big, small objects swapped out on disk will waste
  244. # a lot of space. If you page is too small, there is less space in the swap
  245. # file (assuming you configured the same number of total swap file pages).
  246. #
  247. # If you use a lot of small objects, use a page size of 64 or 32 bytes.
  248. # If you use a lot of big objects, use a bigger page size.
  249. # If unsure, use the default 🙂
  250. vm-page-size 32
  251. # Number of total memory pages in the swap file.
  252. # Given that the page table (a bitmap of free/used pages) is taken in memory,
  253. # every 8 pages on disk will consume 1 byte of RAM.
  254. #
  255. # The total swap size is vm-page-size * vm-pages
  256. #
  257. # With the default of 32-bytes memory pages and 134217728 pages Redis will
  258. # use a 4 GB swap file, that will use 16 MB of RAM for the page table.
  259. #
  260. # It’s better to use the smallest acceptable value for your application,
  261. # but the default is large in order to work in most conditions.
  262. vm-pages 134217728
  263. # Max number of VM I/O threads running at the same time.
  264. # This threads are used to read/write data from/to swap file, since they
  265. # also encode and decode objects from disk to memory or the reverse, a bigger
  266. # number of threads can help with big objects even if they can’t help with
  267. # I/O itself as the physical device may not be able to couple with many
  268. # reads/writes operations at the same time.
  269. #
  270. # The special value of 0 turn off threaded I/O and enables the blocking
  271. # Virtual Memory implementation.
  272. vm-max-threads 4
  273. ############################### ADVANCED CONFIG ###############################
  274. # Hashes are encoded in a special way (much more memory efficient) when they
  275. # have at max a given numer of elements, and the biggest element does not
  276. # exceed a given threshold. You can configure this limits with the following
  277. # configuration directives.
  278. hash-max-zipmap-entries 512
  279. hash-max-zipmap-value 64
  280. # Similarly to hashes, small lists are also encoded in a special way in order
  281. # to save a lot of space. The special representation is only used when
  282. # you are under the following limits:
  283. list-max-ziplist-entries 512
  284. list-max-ziplist-value 64
  285. # Sets have a special encoding in just one case: when a set is composed
  286. # of just strings that happens to be integers in radix 10 in the range
  287. # of 64 bit signed integers.
  288. # The following configuration setting sets the limit in the size of the
  289. # set in order to use this special memory saving encoding.
  290. set-max-intset-entries 512
  291. # Similarly to hashes and lists, sorted sets are also specially encoded in
  292. # order to save a lot of space. This encoding is only used when the length and
  293. # elements of a sorted set are below the following limits:
  294. zset-max-ziplist-entries 128
  295. zset-max-ziplist-value 64
  296. # Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in
  297. # order to help rehashing the main Redis hash table (the one mapping top-level
  298. # keys to values). The hash table implementation redis uses (see dict.c)
  299. # performs a lazy rehashing: the more operation you run into an hash table
  300. # that is rhashing, the more rehashing “steps” are performed, so if the
  301. # server is idle the rehashing is never complete and some more memory is used
  302. # by the hash table.
  303. #
  304. # The default is to use this millisecond 10 times every second in order to
  305. # active rehashing the main dictionaries, freeing memory when possible.
  306. #
  307. # If unsure:
  308. # use “activerehashing no” if you have hard latency requirements and it is
  309. # not a good thing in your environment that Redis can reply form time to time
  310. # to queries with 2 milliseconds delay.
  311. #
  312. # use “activerehashing yes” if you don’t have such hard requirements but
  313. # want to free memory asap when possible.
  314. activerehashing yes
  315. ################################## INCLUDES ###################################
  316. # Include one or more other config files here.  This is useful if you
  317. # have a standard template that goes to all redis server but also need
  318. # to customize a few per-server settings.  Include files can include
  319. # other files, so use this wisely.
  320. #
  321. # include /path/to/local.conf
  322. # include /path/to/other.conf

中文说明:

1,是否以后台进程运行,默认为no
daemonize no

2,如以后台进程运行,则需指定一个pid,默认为/var/run/redis.pid
pidfile /var/run/redis.pid

3,监听端口,默认为6379
port 6379

4,绑定主机IP,默认值为127.0.0.1(注释)
bind 127.0.0.1

5,超时时间,默认为300(秒)
timeout 300

6,日志记录等级,有4个可选值,debug,verbose(默认值),notice,warning
loglevel verbose

7,日志记录方式,默认值为stdout
logfile stdout

8,可用数据库数,默认值为16,默认数据库为0
databases 16

9,指出在多长时间内,有多少次更新操作,就将数据同步到数据文件。这个可以多个条件配合,比如默认配置文件中的设置,就设置了三个条件。

900秒(15分钟)内至少有1个key被改变
save 900 1
300秒(5分钟)内至少有10个key被改变
save 300 10

10,存储至本地数据库时是否压缩数据,默认为yes
rdbcompression yes

11,本地数据库文件名,默认值为dump.rdb
dbfilename /root/redis_db/dump.rdb

12,本地数据库存放路径,默认值为 ./
dir /root/redis_db/

13,当本机为从服务时,设置主服务的IP及端口(注释)
slaveof <masterip> <masterport>

14,当本机为从服务时,设置主服务的连接密码(注释)
masterauth <master-password>

15,连接密码(注释)
requirepass foobared

16,最大客户端连接数,默认不限制(注释)
maxclients 128

17,设置最大内存,达到最大内存设置后,Redis会先尝试清除已到期或即将到期的Key,当此方法处理后,任到达最大内存设置,将无法再进行写入操作。(注释)
maxmemory <bytes>

18,是否在每次更新操作后进行日志记录,如果不开启,可能会在断电时导致一段时间内的数据丢失。因为redis本身同步数据文件是按上面save条件来同步的,所以有的数据会在一段时间内只存在于内存中。默认值为no
appendonly yes

19,更新日志文件名,默认值为appendonly.aof(注释)
appendfilename /root/redis_db/appendonly.aof

20,更新日志条件,共有3个可选值。no表示等操作系统进行数据缓存同步到磁盘,always表示每次更新操作后手动调用fsync()将数据写到磁盘,everysec表示每秒同步一次(默认值)。
appendfsync everysec

21,是否使用虚拟内存,默认值为no
vm-enabled yes

22,虚拟内存文件路径,默认值为/tmp/redis.swap,不可多个Redis实例共享
vm-swap-file /tmp/redis.swap

23,将所有大于vm-max-memory的数据存入虚拟内存,无论vm-max-memory设置多小,所有索引数据都是内存存储的 (Redis的索引数据就是keys),也就是说,当vm-max-memory设置为0的时候,其实是所有value都存在于磁盘。默认值为0。
vm-max-memory 0

24,虚拟内存文件以块存储,每块32bytes
vm-page-size 32

25,虚拟内在文件的最大数
vm-pages 134217728

26,可以设置访问swap文件的线程数,设置最好不要超过机器的核数,如果设置为0,那么所有对swap文件的操作都是串行的.可能会造成比较长时间的延迟,但是对数据完整性有很好的保证.
vm-max-threads 4

27,把小的输出缓存放在一起,以便能够在一个TCP packet中为客户端发送多个响应,具体原理和真实效果我不是很清楚。所以根据注释,你不是很确定的时候就设置成yes
glueoutputbuf yes

28,在redis 2.0中引入了hash数据结构。当hash中包含超过指定元素个数并且最大的元素没有超过临界时,hash将以一种特殊的编码方式(大大减少内存使用)来存储,这里可以设置这两个临界值
hash-max-zipmap-entries 64

29,hash中一个元素的最大值
hash-max-zipmap-value 512

30,开启之后,redis将在每100毫秒时使用1毫秒的CPU时间来对redis的hash表进行重新hash,可以降低内存的使用。当你的使 用场景中,有非常严格的实时性需要,不能够接受Redis时不时的对请求有2毫秒的延迟的话,把这项配置为no。如果没有这么严格的实时性要求,可以设置 为yes,以便能够尽可能快的释放内存
activerehashing yes

 

可以参考:

Redis的部署使用文档  http://www.elain.org/?p=505

========================================================

安装PHP的Redis扩展

 

先去下载https://github.com/nicolasff/phpredis/downloads

#wget https://github.com/nicolasff/phpredis/downloads

# tar -zxvf nicolasff-phpredis-2.1.3-124-gd4ad907.tar.gz
# mv nicolasff-phpredis-d4ad907 php-5.3.8/ext/phpredis/
# cd php-5.3.8/ext/phpredis/
# /usr/local/php/bin/phpize
# ./configure –with-php-config=/usr/local/php/bin/php-config
# make && make install

 

配置php.ini

vi /usr/local/php/lib/php.ini
(加入:
extension=redis.so
)
先要看看有没有extension_dir=/…….
重启apache或者nginx

# /usr/local/apache2/bin/apachectl restart

测试代码:

  1. <?php
  2. $redis = new Redis();
  3. $redis->connect(‘127.0.0.1’,6379);
  4. $redis->set(‘test’,‘hello world!’);
  5. echo $redis->get(‘test’);
  6. ?>

 

 

参考:

Linux(CentOS 5.5) Redis 安装及RedisPHP拓展安装应用

http://www.linuxidc.com/Linux/2011-08/41404.htm
安装redis和phpredis模块

http://skandgjxa.blog.163.com/blog/static/14152982011712112933816/

 

RHEL5下编译安装Redis及其PHP扩展库

http://hi.baidu.com/zjstandup/blog/item/9f38b825d379c96c35a80f7f.html

打赏

转载请注明:苏demo的别样人生 » Redis以及Redis的php扩展安装无错版

   如果本篇文章对您有帮助,欢迎向博主进行赞助,赞助时请写上您的用户名。
支付宝直接捐助帐号oracle_lee@qq.com 感谢支持!
喜欢 (0)or分享 (0)