python2.7連線操作redis的幾種方法
python版本:2.7
首先需要先安裝redis模組:
wget
tar zxvf redis-2.10.3.tar.gz
cd redis-2.10.3
python setup.py install
備註:安裝方法可以參考INSTALL檔案內容
#cat INSTALL
Please use
python setup.py install
and report errors to Andy McCurdy (sedrik@gmail.com)
然後開始匯入redis模組
[root@test ~/python]#python
Python 2.7.12 (default, Jun 1 2018, 14:00:01)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import redis
>>>
以下是操作redis的四種方法:
#cat 1.py
#encoding=utf-8
import redis
r = redis.StrictRedis(host='localhost', port=6379)
print r.ping()
#cat 2.py
#encoding=utf-8
import redis
r = redis.StrictRedis(host='127.0.0.1', port=6379, db=0)
print r.ping()
#cat 3.py
#encoding=utf-8
import redis
pool = redis.ConnectionPool(host='localhost', port=6379, decode_responses=True)
r = redis.Redis(connection_pool=pool)
print r.ping()
#cat 4.py
# -*- encoding: UTF-8 -*-
import redis
r = redis.Redis(host='localhost', port=6379, decode_responses=True)
print r.ping()
首先需要先安裝redis模組:
wget
tar zxvf redis-2.10.3.tar.gz
cd redis-2.10.3
python setup.py install
備註:安裝方法可以參考INSTALL檔案內容
#cat INSTALL
Please use
python setup.py install
and report errors to Andy McCurdy (sedrik@gmail.com)
然後開始匯入redis模組
[root@test ~/python]#python
Python 2.7.12 (default, Jun 1 2018, 14:00:01)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import redis
>>>
以下是操作redis的四種方法:
#cat 1.py
#encoding=utf-8
import redis
r = redis.StrictRedis(host='localhost', port=6379)
print r.ping()
#cat 2.py
#encoding=utf-8
import redis
r = redis.StrictRedis(host='127.0.0.1', port=6379, db=0)
print r.ping()
#cat 3.py
#encoding=utf-8
import redis
pool = redis.ConnectionPool(host='localhost', port=6379, decode_responses=True)
r = redis.Redis(connection_pool=pool)
print r.ping()
#cat 4.py
# -*- encoding: UTF-8 -*-
import redis
r = redis.Redis(host='localhost', port=6379, decode_responses=True)
print r.ping()
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15498/viewspace-2156432/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 幾種常見的資料庫連線方法資料庫
- php連線mysql資料庫的幾種方法PHPMySql資料庫
- xml操作的幾種方法XML
- go~連線redis的方法GoRedis
- sqlplus連線資料庫的幾種方法SQL資料庫
- 批量殺死MySQL連線的幾種方法詳解MySql
- golang 幾種字串的連線方式Golang字串
- 幾種表的連線方式(SQL)SQL
- 使用ABAP操作Excel的幾種方法Excel
- VMware連線網路的幾種方式
- 資料庫連線的方法種種資料庫
- java操作redis叢集連線池JavaRedis
- Golang 連線池的幾種實現案例Golang
- mybatis連線資料庫的幾種方式MyBatis資料庫
- Python 連線 MySQL 的幾種姿勢PythonMySql
- oracle sql內連線_左(右)連線_全外連線_幾種寫法OracleSQL
- Jedis使用連線池操作redis叢集Redis
- PHP 技術卡片 - 字串連線的幾種方式PHP字串
- 外部連線不上redis的解決方法Redis
- JDBC 連線oracle三種方法JDBCOracle
- Python字串連線的5種方法Python字串
- 【LISTENER】資料庫連線串的幾種寫法資料庫
- 幾種連線資料庫的OLEDB驅動程式資料庫
- Laravel redis 連不同的連線LaravelRedis
- Spring連線資料庫的幾種常用的方式Spring資料庫
- COOKIE的幾種操作方式Cookie
- windows系統下實現Redis的配置與連線操作WindowsRedis
- redis的幾種型別解析Redis型別
- 淺談SQL Server中的三種物理連線操作SQLServer
- mysql資料庫連表查詢的幾種方法MySql資料庫
- 使用 Java 測試網路連通性的幾種方法Java
- Java裡連線字串的幾種方式以及優缺點Java字串
- Python連線Redis連線配置PythonRedis
- 資料庫的連線、索引和Redis的五種資料型別及其操作命令、使用場景資料庫索引Redis資料型別
- UITableView設定全屏分隔線的幾種方法比較UIView
- 18 Redis 連線Redis
- Stream 的幾種中間操作
- redis加鎖的幾種實現Redis