ちょうどあなたが(おそらくJSONまたは類似としてエンコード)の値として、各内側のリスト( `[1、...]`など)を保存する必要がありますように漬物
# store_objects_in_redis.py
'''
Pickle (dumps) & set to store
Get & and unpickle (loads) to retrieve
#
Courtesy: Armin Ronacher, http://flask.pocoo.org/snippets/73/
'''
import redis
from pickle import loads, dumps
# Create client with default connection
client = redis.client.StrictRedis()
# An example complex object
stored_object = [{1,2,3}, {'a':1,'b':2,'c':3}, ['foo', 'bar']]
# store
client.set('obj', dumps(stored_object))
# retrieve
retrieved_object = loads(client.get('obj'))
# compare
print(stored_object==retrieved_object, '\n', stored_object, '\n', retrieved_object)
'''
Prints (Running in windows7)
== RESTART: K:/.../REDIS/store_objects_in_redis.py ==
True
[{1, 2, 3}, {'c': 3, 'b': 2, 'a': 1}, ['foo', 'bar']]
[{1, 2, 3}, {'c': 3, 'b': 2, 'a': 1}, ['foo', 'bar']]
'''
音声を使用。キーは外側のリスト内の位置にする必要があります。接頭辞には全体の名前を付ける必要があります。サブリストにアクセスするこの方法は簡単です。 – Alfe
@Alfeだから、私は(zadd)[http://redis-py.readthedocs.io/en/latest/#redis.Redis.zadd]を使うべきですか?私はredisリストを使用することは可能だとは思わないので、 – 91DarioDev
Redisはリストもサポートしていますが、私はそれを文字列にのみ使用しています。 json-solutionは爪のように見える私のハンマーに。しかし、ネイティブにリストを自由に保存することをお勧めします。なぜそれは不可能だと思いますか? – Alfe