wyp*_*wyp 6 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')
print r1.lrange('a',start=0,end=-1)
print r2.lrange('a',start=0,end=-1)
Run Code Online (Sandbox Code Playgroud)
然后我得到了这个结果:
['test', '1', 'test', '2', 'test', '3', 'test', '4']
['test', '1', 'test', '2', 'test', '3', 'test', '4']
Run Code Online (Sandbox Code Playgroud)
虽然我使用不同的数据库,但对于相同的密钥,所有的值都被放入.谢谢.
fre*_*ish 18
DB应该是从零开始的数字索引 (显然限制为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)
Run Code Online (Sandbox Code Playgroud)