1

Let say I have following data in redis:

key               value

user-1-xxxx       data1

user-1-yyyy       data2

user-1-tttt       data3

So, can I get all above records by wildcard user-1-* (including the keys and values).

I tried KEYS user-1-* , but it only give all the keys, not their values.

If it is not support wildcard searching, can you recommend a way to store this kind of data.

I am using golang redigo by the way.

dev-jim
  • 2,404
  • 6
  • 35
  • 61

2 Answers2

1

Redis isn't designed for looking up data by value. You can either index the data yourself (see https://redis.io/topics/indexes) or use a search engine for that, such as http://redisearch.io.

Itamar Haber
  • 47,336
  • 7
  • 91
  • 117
1

You probably want to structure your data into a hash instead of single keys.

> HSET user-1 xxxx data1
> HSET user-1 yyyy data2
> HSET user-1 tttt data3

If you want to get everything on the user run HGETALL user-1 but if you just want to get a specific part, go for HGET user-1 xxx.

stockholmux
  • 1,169
  • 11
  • 24
  • @ stockholmux i used this like `reply, err := conn.Cmd("HGETALL", cacheKey).Map()` but here i am able to get only one record while i want all records which have same `cacheKey`, could you plz help me to out of this. – saddam Mar 30 '18 at 14:56
  • 1
    @saddam Each key can only hold one "record" – stockholmux Apr 03 '18 at 12:39
  • @ stockholmux thank you for your reply, one question here- can we use filter on colomns like search on date to get records. – saddam Apr 03 '18 at 13:38
  • 1
    @saddam nope. Redis doesn't work that way. If you have needs for filtering/searching, you should look at RediSearch (Redis Search engine) – stockholmux Apr 03 '18 at 16:09