Closed clmnin closed 2 years ago
Hello,
You didn't set decode_responses
to True
when you initialized your ConnectionPool
.
The decode_responses
is passed to the ConnectionPool object of the client when you create it.
Redis ConnectionPool are used by default when you initialize a Redis Client. Do you have a specific reason to initialize the ConnectionPool beforehand ?
You can skip the ConnectionPool part, and set up your rejson Client
with the max_connection
set to 10
and it would automatically create a connection pool managed by the Rejson client, that you can access atrj.connection_pool
.
Here you can see the Redis client creating the ConnectionPool if you don't provide it at creation.
Hope this helps
@bentsku
I'm using both rejson
and redisearch
. So my reasoning behind initializing a pool prehand is so that I can use the same pool for both the clients
import redis
import redisearch
import rejson
redis_pool = None
def redis_pool_get_con():
return redis.Redis(connection_pool=redis_pool)
def redis_create_pool() -> None:
global redis_pool
redis_pool = redis.ConnectionPool.from_url("redis://localhost", max_connections=10)
redis_create_pool()
rs = redisearch.Client(index_name, conn=redis_pool_get_con())
rj = rejson.Client(decode_responses=True, connection_pool=redis_pool)
Is there a better way to use RediSearch and ReJSON?
I don't know if there's a better way for your case, but I've checked in the RediSearch python client, and they use decode_responses
as True
for their ConnectionPool
. So both ReJSON and RediSearch needs their ConnectionPool to have decode_responses
set to True
.
So for your case, when you create your ConnectionPool
, set decode_responses
to True
.
def redis_create_pool() -> None:
global redis_pool
redis_pool = redis.ConnectionPool.from_url("redis://localhost", max_connections=10, decode_responses=True)
It should fix your Exception.
Thank you.
I get decoding exception when I use a redis-pool along with rejson client.
I'll use the same code as the
Usage Example
in READMEThis is the diff
Exception