redis操作+python接続redis(StrictRedis)
3136 ワード
1.1:仮想環境py_django,通信インストールパッケージredis(推奨)pip 3 install redis
1.2:仮想環境py_django,通信インストールパッケージredis easy_install redis
1.3:中⽂官通信-クライアントへredisパッケージのソースコードをダウンロードし、応用ソースコードのインストールを一歩一歩実行させる
wget https://github.com/andymccurdy/redis-py/archive/master.zip
unzip master.zip
cd redis-py-master
sudo python setup.py install
from redis import StrictRedis
if __name__=="__main__":
try:
# StrictRedis , redis
# sr = StrictRedis(host='localhost', port=6379, db=0) # StrictRedis 。 db=0, (redis 16 )
sr = StrictRedis() # 。
# name, ( name ; )
result = sr.set('name',' ') # Boolean 。 True, False
# name
result = sr.get('name') # , None
# name ( , )
result = sr.delete('name') # , 0
#
result = sr.keys() # , 。
except Exception as e:
print(e)
keys
string
hash
list
set
zset
exists
set
hset
lpush
sadd
zadd
type
setex
hmset
rpush
smembers
zrange
delete
mset
hkeys
linsert
srem
zangebyscore
expire
append
hvals
lrange
zscore
getrange
get
hget
lset
zrem
ttl
mget
hmget
lrem
zremrangebyscore
key
hdel
from redis import StrictRedis
if __name__ == "__main__":
try:
# StrictRedis , redis
sr = StrictRedis(host='localhost', port=6379, db=0)
# redis , ( )
pipeline = sr.pipeline()
#
pipeline.multi()
pipeline.hset("user", "name", " ")
pipeline.expire("user", 3600) # redis
# ( )
pipeline.execute()
except Exception as e:
print(e)