RedisJSON / redisjson-py

An extension to redis-py for using Redis' ReJSON module
https://redisjson.io
BSD 2-Clause "Simplified" License
160 stars 34 forks source link

How to search in a list? #47

Open avico78 opened 3 years ago

avico78 commented 3 years ago

I see a key pointing to list of json :

redis_json_client.jsonset('customers', Path.rootPath(), { "customers": []})

example of insreted json customer_json:

 {
  "customer_status": "Active",
  "first_name": "Leonard",
  "last_name": "Cohen",
  "customer_no": 1
}

So now I append each of the json as following:

redis_json_client.jsonarrappend('customers', Path('.customers'), customer_json)

I'd like to preform a search finding specific customer_no I tried something like:

customer_redis = redis_json_client.jsonget('customers', Path('customer_no'),370471789)

Q: 1.The reaosn for creating a list of json is that i'd like to some category collection in redis ,i wonder how bad it effect the performance , I could also assign the json as : key,customer_json instead of key,[customer_json]

2.How could i preform a search for specific json where key holds a list of json as desribe above?

gkorland commented 3 years ago
  1. When searching in an it's O(n) where n is the length of the array, while when you use map it's O(1)
  2. To search for a specific JSON that hold a specific value you'll have to use RediSearch, we are going to release in the next few weeks this capability.

Meanwhile you can this preview docker redislabs/redisearch:feature-search-json

docker run -p 6379:6379 redislabs/redisearch:feature-search-json