Pergunta

OK, in REDIS if i simply want to set up keys = a channel name and value = either paid or free...

so eventually ill have a list 100s, 1000s, etc etc of keys and values where the key's value will either be paid or free.

     channelName, paid or free

so,then i want to come and search and ask the db give me all the channels whose value = free

whats the best way/efficent way to set this up?

i basically want to query and return a list of all the keys that equal a certain value in a list or dict...

Foi útil?

Solução

You can use sorted sets, and the member value to be 0 (free) or 1 (paid).

In a single key, you can store the members of the sorted set, and each member is given a decimal value. Abstracting the free and paid to be 0 and 1 values, you can add members (i.e. in your case, channels) to the set, and later query those.

127.0.0.1:6379> ZADD mychannels 0 1stchannel 1 2ndchannel 1 3rdchannel 0 4thchannel
(integer) 4
127.0.0.1:6379> ZRANGEBYSCORE mychannels 0 0 /* Querying free channels */
1) "1stchannel"
2) "4thchannel"
127.0.0.1:6379> ZRANGEBYSCORE mychannels 1 1 /* Querying paid channels */
1) "2ndchannel"
2) "3rdchannel"
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top