Python interview redis1 install Redisa on Linux) download
$ wget http://download.redis.io/releases/redis-3.0.5.tar.gz
b) Compile
# yum Install gcc tcl# tar-zxf redis-3.0.5.tar.gz# cd redis-3.0.5# make# make test# sudo make install
This allows you to run file Redis-server and so on from REDIS-3.0.5/SRC to/usr/local/bin
c) Start the service (port 6379 to open)
$ redis-server
Or
$ redis-server/path/to/redis.conf
1428:m 11:47:33.817 # warning:the TCP Backlog setting of 511 cannot be enforced BECAUSE/PROC/SYS/NET/CORE/SOMAXCO NN is set to the lower value of 128.
1428:m 11:47:33.817 # Server started, Redis version 3.0.5
1428:m 11:47:33.818 # WARNING Overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add ' vm.overcommit_memory = 1 ' to/etc/sysctl.conf and then reboot or run the command ' Sysctl vm.overcom Mit_memory=1 ' for the take effect.
1428:m 11:47:33.818 # WARNING You has Transparent Huge Pages (THP) support for enabled in your kernel. This would create latency and memory usage issues with Redis. To fix this issue run the command ' echo never >/sys/kernel/mm/transparent_hugepage/enabled ' as root, and add it to you R/etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
d) Server configuration to remove the warning above
Operation as Root user
1) Change kernel parameters: Somaxconn
The default value for this kernel parameter is typically 128, which is not large enough for a service program that is heavily loaded.
It will usually be changed to 2048 or greater.
# echo 2048 >/proc/sys/net/core/somaxconn
Save after reboot:
Add such as the following in the/etc/sysctl.conf
Net.core.somaxconn = 2048
And then run it in the terminal.
# sysctl-p
2) Change Vm.overcommit_memory
overcommit_memory Specifies the kernel policy for memory allocation. The value can be 0, 1, 2.
0, indicates that the kernel will check if there is enough memory available for the process to use, assuming that there is enough memory available, the memory request agrees. Otherwise, the memory request fails and the error is returned to the application process.
1. Indicates that the kernel agrees to allocate all physical memory regardless of the current state of memory.
2, which means the kernel agrees to allocate more memory than the sum of all physical memory and swap space
# vi/etc/sysctl.conf
Add the following line:
Vm.overcommit_memory=1
Set to persist after reboot, Run command:
# sysctl Vm.overcommit_memory=1
3) Transparent_hugepage
Disable transparent giant page memory configuration for improved performance
To view the current status:
$ cat/sys/kernel/mm/transparent_hugepage/enabled
[Always] madvise never
Description of the parameters
Never off, not using transparent memory
Alway use transparent memory as much as possible. Scan memory with 512 4k pages to integrate. Integrated into a 2M page
Madvise Avoid changing memory footprint
Disable transparent giant page memory:
# echo never >/sys/kernel/mm/transparent_hugepage/enabled# cat/sys/kernel/mm/transparent_hugepage/enabled
Always madvise [never]
Permanently disabled, add the command to the rc.local:
# VI Rc.local
... # Redis required never for Transparent_hugepageif test-f/sys/kernel/mm/transparent_hugepage/enabled; Then echo never >/sys/kernel/mm/transparent_hugepage/enabledfiif test-f/sys/kernel/mm/transparent_hugepage /defrag; Then
e) redis.conf Configuration
Refer to the following redis.conf configuration items: Redis Configuration Specific explanation
http://blog.csdn.net/ithomer/article/details/9232891
2 redis-py
Redis-py This is the most mature Python client development package for Redis right now.
Redis Home Page:
Https://github.com/andymccurdy/redis-py
A) Download the source code
$ git clone https://github.com/andymccurdy/redis-py.git
b) Installation
$ cd redis-py$ sudo python for redis install
3 Hiredis
Hiredis is the C interface of the Redis database, which can only be used under Linux at the moment, and several key functions will be able to operate the Redis database.
Hiredis is the official Redis-designated C Language client development package that supports Redis's complete set of commands, pipelines, and event-driven programming.
Hiredis Home Page:
Https://github.com/redis/hiredis
A) Download and install
$ git clone https://github.com/redis/hiredis.git$ cd hiredis$ make$ sudo make install
Examples:
http://blog.csdn.net/mfc_vc_andy/article/details/8095839
p=304 ">http://www.leoox.com/?
p=304
4 hiredis-py
Python's wrapper class for Hiredis.
Home:
Https://github.com/redis/hiredis-py
a) Download
$ wget https://pypi.python.org/packages/source/h/hiredis/hiredis-0.2.0.tar.gz
b) Installation
$ tar zxf hiredis-0.2.0.tar.gz$ cd hiredis-0.2.0$ python setup.py build$ sudo python setup.py install
5 python Operation Redis
http://blog.csdn.net/chosen0ne/article/details/7319807
http://blog.csdn.net/chenggong2dm/article/details/6102540
6 Graceful Close Redis-server
$ redis-cli-h 127.0.0.1-p 6379 shutdown
7 Redis-server enable password and simple sample a) copy redis.conf to/etc/b) create Redis Database Storage folder
$ sudo mkdir/var/redis
c) Change/etc/redis.conf
$ sudo vi redis.conf
The only changes to the content are as follows:
Daemonize Yesloglevel Warninglogfile/var/log/redis.logdir/var/redis/requirepass Abc123
d) Start and close services
$ sudo redis-server/etc/redis.conf with password off service: $ redis-cli-h 127.0.0.1-p 6379-a Abc123 shutdown
e) Clientpython
At this point the client needs to connect to the server with password:
Import Redisr=redis. Strictredis (host= "127.0.0.1", port=6379, Db=0, password= "Abc123") R.set ("City", "Shanghai") R.get ("City")
Set the expiration time for key. For example, we only save 60 seconds of data, which can be set:
R.expire ("City", 60)
Immediately follow it:
R.get ("City") Shanghai
Visit again in 60 seconds:
R.get ("City")
Without.
8 Appendices
More specific sample references:
Https://github.com/andymccurdy/redis-py
A complete reference to Redis:
Http://www.redis.net.cn/tutorial/3505.html
Python Interview with Redis