Skip to content

Commit

Permalink
Return Redis sets as Python lists
Browse files Browse the repository at this point in the history
In some (rare) cases, the sets from a Redis response contain nested
types that are not hashable in Python, for example maps. To handle these
cases uniformly, always return Python lists for Redis sets. The elements
will still be unique, relying on the correctness of data arriving from
the server.
  • Loading branch information
gerzse committed Jul 3, 2024
1 parent 64e3394 commit 72dfc2f
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ MANIFEST
.venv
**/*.so
hiredis.egg-info
.idea
7 changes: 0 additions & 7 deletions src/reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ static void *tryParentize(const redisReadTask *task, PyObject *obj) {
PyDict_SetItem(parent, last_key, obj);
}
break;
case REDIS_REPLY_SET:
assert(PyAnySet_CheckExact(parent));
PySet_Add(parent, obj);
break;
default:
assert(PyList_CheckExact(parent));
PyList_SET_ITEM(parent, task->idx, obj);
Expand Down Expand Up @@ -162,9 +158,6 @@ static void *createArrayObject(const redisReadTask *task, size_t elements) {
case REDIS_REPLY_MAP:
obj = PyDict_New();
break;
case REDIS_REPLY_SET:
obj = PySet_New(NULL);
break;
default:
obj = PyList_New(elements);
}
Expand Down

0 comments on commit 72dfc2f

Please sign in to comment.