美文网首页
Python连接redis和mongodb

Python连接redis和mongodb

作者: _Haimei | 来源:发表于2018-06-15 20:13 被阅读32次

python连接redis

import redis
import json
r = redis.StrictRedis('localhost',6379,decode_responses=True)
key = r.keys()
for value in r.sscan_iter('info'):
    value = json.loads(value).get('name')
    print(value)

python连接mongodb

import pymongo
client = pymongo.MongoClient(host = 'localhost',port = 27017)
db = client.user  #创建user数据库
my_set = db.students  #创建students集合
result = my_set.insert([{"name":"lingling","age":20,"phone":"13521386027"},{"name":"Daming","age":15,"phone":"13521385024"}])
print(result)

相关文章

网友评论

      本文标题:Python连接redis和mongodb

      本文链接:https://www.haomeiwen.com/subject/lnameftx.html