Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Redis for python中写入多个数据库_Python_Database_Redis_Key Value Store - Fatal编程技术网

在Redis for python中写入多个数据库

在Redis for python中写入多个数据库,python,database,redis,key-value-store,Python,Database,Redis,Key Value Store,我想将一些值写入不同的数据库,这是我的代码: import redis r1 = redis.Redis(host='127.0.0.1', port=6379, db = 'db1') r2 = redis.Redis(host='127.0.0.1', port=6379, db = 'db2') numList = ['4', '3', '2', '1'] for num in numList: r1.lpush('a', num) r2.lpush('a', 'test

我想将一些值写入不同的数据库,这是我的代码:

import redis

r1 = redis.Redis(host='127.0.0.1', port=6379, db = 'db1')
r2 = redis.Redis(host='127.0.0.1', port=6379, db = 'db2')

numList = ['4', '3', '2', '1']

for num in numList:
   r1.lpush('a', num)
   r2.lpush('a', 'test')

print r1.lrange('a',start=0,end=-1)
print r2.lrange('a',start=0,end=-1)
然后我得到了这个结果:

['test', '1', 'test', '2', 'test', '3', 'test', '4']
['test', '1', 'test', '2', 'test', '3', 'test', '4']
虽然我使用不同的数据库,但对于同一个键,所有的值都放进去了。 谢谢。

星展银行应该是(很明显,限额是15)。试用

r1 = redis.Redis(host='127.0.0.1', port=6379, db = 0)
r2 = redis.Redis(host='127.0.0.1', port=6379, db = 1)

你帮了我很多。谢谢。是的,我使用几乎相同的代码redis\u server=redis.StrictRedis(host=“localhost”,port=6379,charset=“utf-8”,decode\u responses=True,db=0)没有15个数据库的限制。您可以将redis.config文件中的数据库数量设置为所需的数量,然后选择介于0和'databases'-1'之间的dbid。@MikeL我差不多6年前写过这个答案。我不记得我为什么写这个限制。也许当时有这样的限制,但现在已经不存在了。谁知道呢?我不记得了。