Automatically secondary index creation in Redis

623 views
Skip to first unread message

N Bijalwan

unread,
Mar 28, 2018, 7:21:23 AM3/28/18
to Redis DB
I want to use secondary indexes or some methodology which can help me query the data inserted in Redis. Is there a way to avoid explicitly index creation for each insertion in Redis.

For example :

having three insertion

HMSET user:1 id 1 username antirez ctime 1444809424 age 38
HMSET user:2 id 2 username maria ctime 1444808132 age 42
HMSET user:3 id 3 username jballard ctime 1443246218 age 33 


Can the underline indexes be created themselves using some user defined schema and we can query db it using

HGET username jballard

without explicitly creating indexes.

one way is to create key itself with values like

HMSET user:1:antirez:1444809424:38 id 1 username antirez ctime 1444809424 age 38

and query it like

KEYS user:*:antirez:*

but then any change in values require change in keys and also

Is there a better way to do that.

Itamar Haber

unread,
Mar 28, 2018, 7:33:36 AM3/28/18
to Redis DB
Hello N Bijalwan,

No, Redis does not offer automatic index creation. Also, the approach you've provided using `KEYS` is not recommended - see the warning in the command's documentation.

For more information about secondary indices in Redis, please refer to https://redis.io/topics/indexes

Cheers,

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+unsubscribe@googlegroups.com.
To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.



--

Itamar Haber | Technology Evangelist
Redis Labs ~/redis

Mobile: +972 (54) 567 9692
Twitter: @itamarhaber
Skype: itamar.haber

Marc Gravell

unread,
Mar 28, 2018, 8:04:02 AM3/28/18
to redi...@googlegroups.com
Note: some additional modules etc provide functionality *comparable* to secondary indexing. For example, I suspect that RediSearch (https://github.com/RedisLabsModules/RediSearch) might work with that data and those queries.
Regards,

Marc
Reply all
Reply to author
Forward
0 new messages