开发者

redis and tags for a large video site

开发者 https://www.devze.com 2023-04-11 14:05 出处:网络
My question is regarding tags and searching, for a tube/flash based video clip site. I have apx 100,000 videos which I want to organize using Redis.

My question is regarding tags and searching, for a tube/flash based video clip site.

I have apx 100,000 videos which I want to organize using Redis.

Each video has the following:

Title, length, tags

I've been adding the clips with the following

hset video:id1 title  "A funny clip"
hset video:id1 length "22 secs"
hset video:id1 tags   "funny,accident,cat"

hset video:id2 title  "Falling of a chair"
hset video:id2 length "33 secs"
hset video:id2 tags   "funny,chair,kids"

hset video:id3 title  "Pool party"
hset video:id3 length "17 secs"
hset video:id3 tags   "funny,pool,accident"

What do I do now to allow for searching by tags.

I'd like to be able to do a search for all the clips which hav开发者_如何学运维e certain tags.


You're going the wrong way around. In redis you sort of need to think backwards. If you want to search for a certain tag, you need a mapping from tag to objects, instead of from object to tags. In Redis, you need to define your own indexes!

So if you want to be able to search for all videos with a certain tag, create a set for each tag, and add the video id's with that tag to the set.


The best is to create a list for each tag in which you add the video id

rpush funny id1 id2 id3

EDIT:

You can find ideas about how to search for incomplete tags here :

http://antirez.com/post/autocomplete-with-redis.html


What do I do now to allow for searching by tags.

Redis doesn't support any type of ad-hoc data querying. Although there is a KYES command which allows you to search for keys with certain pattern, it's only meant to be used for debugging or similar operations since it's performance is dependent on amount of keys in your database.

You can however create dedicated set structures for your tags, where each set would hold a collection of video IDs assigned to certain tag.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号