The current LSET can only support a single index, like the following, LSET key index value, I hope it can support setting multiple indexes at the same time, for example: LSET KEY index0 value0 index1 value1 ...

Comment From: madolson

Can you describe your use case a little bit? Using Lists this way is a bit of an anti-pattern, you should be doing push/pop operations primarily.

However, this could change your access pattern from O(N^2) to O(N), so that is at least a compelling reason to consider this.

Comment From: ffbh123456

@madolson I currently want to store MySQL table to Redis I use the id of the row as the key. I have 4 columns: column1, column2, column3, column4. their corresponding index in the list are 0, 1, 2, 3

INSERT A RECORD

RPUSH key column1 column2 column3 column4

QUERY SOME CONTINUOUS FIELD

LRANGE key index1 index2

DEL

DEL key

UPDATE SOME FIELD

LSET key index1 value1 index2 value2 ... // This feature is currently not available
  1. The use of list here is actually not the best, I think it would be better to use an array, but there seems to be no array type in Redis
  2. LSET key index1 value1 index2 value2 ..., I think you can sort the index first, then update the value of each index sequentially, which the time complexity can be reduced to O(NlogN).
  3. Or is there any other way to store MySQL data in Redis?

Comment From: madolson

Yeah, a list is probably not going to serve you super well, since arbitrary looks up are O(N) of the size of the list. We can optimize the multi-lookup case by sorting, but that is still not a great performance. Are you sure you want to store this data in Redis, it doesn't seem like a great fit for your data?

Have you considered using hashes, and storing each record in its own key?

Comment From: ffbh123456

@madolson Yes, there are more flexible commands in the hash, but it may not be as fast as the list, because the advantages of hash can be reflected when N is large, but my N is very small, only 4. Even if it is O(N), the list may be faster than the hash, but I have not to test this. And I think array is the best, the array should be a commonly used thing, Have you considered adding the array type to Redis ? It would be great if Redis have the following commands to operate the array.

ASET key index1 value1 index2 value2 ...
AGET key index1 index2 ...

Comment From: zuiderkwast

Small hashes are actually stored as ziplists, which is a very compact way of storing data. Small lists are also stored as ziplists. The difference is that hashes also store keys which you don't need, so I understand the point of using lists in this case actually.

I don't think your use case justifies another key type (array), but I do like the idea of extending LSET to set multiple indices. I suggest you implement it and create a PR. :+1:

Otherwise, if you can accept the overhead of a few extra bytes for storing the keys ("1", "2", "3", "4") I think you should use hashes.

Comment From: madolson

I would still not be very inclined for such an LSET command. You can always MULTI-EXEC multiple LSET commands together. Since this isn't solving a very common use case, I wouldn't want to implement a sub-optimal use case.