Pythonはredisとmongodbを接続する
674 ワード
python接続redis
python接続mongodb
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)