Redis3.2安裝並通過Python連線

feelpurple發表於2016-12-06
下載安裝包並解壓
wget -q http://124.202.164.16/files/2125000009862F7A/download.redis.io/releases/redis-3.2.6.tar.gz
tar -xzf redis-3.2.6.tar.gz

編譯
cd redis-3.2.6
make
..
geo.c: In function ‘membersOfAllNeighbors’:
geo.c:355: warning: missing initializer
geo.c:355: warning: (near initialization for ‘myarea.hash.step’)
geo.c:355: warning: missing initializer
geo.c:355: warning: (near initialization for ‘myarea.longitude’)
    LINK redis-server
    INSTALL redis-sentinel
    CC redis-cli.o
    LINK redis-cli
    CC redis-benchmark.o
    LINK redis-benchmark
    INSTALL redis-check-rdb
    CC redis-check-aof.o
    LINK redis-check-aof

Hint: It's a good idea to run 'make test' ;)

make[1]: Leaving directory `/script/redis-3.2.6/src'

安裝
make install

cd src && make install
make[1]: Entering directory `/script/redis-3.2.6/src'

Hint: It's a good idea to run 'make test' ;)

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
make[1]: Leaving directory `/script/redis-3.2.6/src'

啟動Redis伺服器
[root@localhost redis-3.2.6]# redis-server redis.conf &
[1] 11954
[root@localhost redis-3.2.6]# 11954:M 06 Dec 07:32:37.376 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 3.2.6 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 11954
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

11954:M 06 Dec 07:32:37.379 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
11954:M 06 Dec 07:32:37.380 # Server started, Redis version 3.2.6
11954:M 06 Dec 07:32:37.380 # 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.overcommit_memory=1' for this to take effect.
11954:M 06 Dec 07:32:37.387 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will 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 your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
11954:M 06 Dec 07:32:37.387 * DB loaded from disk: 0.000 seconds
11954:M 06 Dec 07:32:37.387 * The server is now ready to accept connections on port 6379

為Python語言安裝Redis客戶端庫
[root@localhost script]# pip install redis hiredis
DEPRECATION: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future version of pip will drop support for Python 2.6
Collecting redis
/usr/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissingwarning.
  SNIMissingWarning
/usr/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading redis-2.10.5-py2.py3-none-any.whl (60kB)
    100% |████████████████████████████████| 61kB 48kB/s 
Collecting hiredis
  Downloading hiredis-0.2.0.tar.gz (46kB)
    100% |████████████████████████████████| 51kB 42kB/s 
Installing collected packages: redis, hiredis
  Running setup.py install for hiredis ... done
Successfully installed hiredis-0.2.0 redis-2.10.5

登入Redis
[root@localhost script]# python
Python 2.6.6 (r266:84292, Nov 22 2013, 12:16:22) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import redis
>>> conn = redis.Redis()
>>> conn.set('hello', 'world')
True
>>> conn.get('hello')
'world'

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26506993/viewspace-2129927/,如需轉載,請註明出處,否則將追究法律責任。

相關文章