support Matrix datatype #370

Closed
guileen opened this Issue Mar 2, 2012 · 2 comments

Comments

Projects
None yet
3 participants

guileen commented Mar 2, 2012

Redis, not only a key-value store, it's an awesome data structure store.

Hash give us some kind of single direction matrix

HSET row col v
HGETALL row

but we can't HGETALL col

if there is a MATRIX data type, we can do

XSET row col v
XROW row
XCOL col

Alternative, is it possible redis provide a command like

HGETALLBYFIELD field
HVALSBYFIELD field

for now, sometimes we have to save 2 Hash

HSET row col v
HSET col row v

Or, worse

SET "row:col" v

that we can't retrieval the same row columns or same column rows.

@ghost

ghost commented Mar 3, 2012

You'd be much better off using a single continuous list for a matrix rather than a hash for each row. In that case, you can quickly retrieve rows with LRANGE. For column retrieval, you'll still need to enumerate all the indices but in 2.6, you can offload that to the server with a Lua script. That makes more sense because your keys are bounded integers anyway and keeping it all together within one key will work better with sharding.

I'm also interested in this feature. I think it could make Redis a very practical numeric datastore for online machine learning systems. One critique I have of @guileen's suggested interface is that it only supports 2-D arrays, I don't see a reason to pick an arbitrary dimension.

For example, if I was manipulating an RGB image matrix stored in Redis I could set the pixel at (20, 25)'s blue intensity to 255.

XSET mymat 20 25 3 255

And retrieve "rows" and "columns" (or slice by dims however) by doing something like

XGET mymat 20 # (get row 20, all color channels)
XGET mymat : 25 1:2 # (get column 25, color channels red and green)

I'm poking into the Redis source for the first time, so I don't know how feasible it is, but preferably the values would be floating point instead of integers.

I'm particularly interested in being able to do basic vectorized operations on a matrix like

XSET mymat 0 0 1
XSET mymat 1 1 2
XMULTIPLY mymat 4
XGET mymat
4 0
0 8

Is this the kind of feature that would ever be merged if someone were to implement it, or is it outside the scope of Redis? If yes, I'd be willing to contribute.

@badboy badboy closed this Jul 7, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment