Jocelyn Mcelveen
Jocelyn Mcelveen

Reputation: 11

Redis How to store array preserving order of keys

I'm trying to save sorted array to Redis, preserving it's order of keys (it's crucial)

[ 'abcdef' => value1, 'abcd' => value2, 'abc' => value3 ]

,and I need to restore it in the same order;

I tried hashes, but when I get the array back, it's realized unordered. For example:

 [ 'abc' => value3, 'abcd' => value2, 'abcded' => value1 ]

I have some ideas about ZADD, but I can't figure out exactly, what I have to do.

Upvotes: 1

Views: 367

Answers (1)

Ryoma
Ryoma

Reputation: 64

I don't understant you mean array: [ 'abc' => value3, 'abcd' => value2, 'abcded' => value1 ], I think this is a hash.

The array should be like: ['abc', 'abcd', 'abcded'], and if your want store in redis, you can parse array to string then store.

Upvotes: 1

Related Questions