简体   繁体   中英

Key-Value Pairs in Redis

I'm planning to use Redis, to store a list of image links associated with a set of keywords for fast retrieval.

But, I'm kinda confused on defining my keys here.

I'd like to have a set of keywords, maybe 3 or 4 as my keys. so, If I search for any of the keyword combination, I get the list of images returned.

How can I define my keys to store multiple words? I know that it's not advisable to have mutable keywords, but I don't want to make changes to the keys later. To explain further:

( 'jack', 'dorsey', 'twitter' ) : [link/to/image1.jpg, link/to/image2.jpg,link/to/image3.jpg]

( 'jack', 'dorsey', 'square' ) : [link/to/image1.jpg, link/to/image2.jpg, link/to/image3.jpg]

Even if I could create bigrams or just trigrams in keys, that would help.

  1. Is this possible?
  2. Is there an alternative?

I don't think its directly possible to do it that way but you could simply do

import redis
import json
r = redis.Redis()
r.rpush(json.dumps(("jack", "dorsey", "twitter"), image)

Then when you want to check something against the key or other you just use the json.dumps of your data structure

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM