How to batch update Redis?

1,564 views
Skip to first unread message

Kai Zhang

unread,
Nov 23, 2016, 2:50:05 AM11/23/16
to Redis DB
Hello all,
     I am a newbie to Redis,My redis store terminal infos such as id, name, status, property etc.There are many terminals will update it's status.But some "fixed“ info will not be modified.So I need to read the terminal info first, then modify the status and key the fixed properties then I will rewrite the redis.What is the best practices for this situation? mget? mset? pipe ? lua script?
many thanks,
zhangkai
2016.11.23

Itamar Haber

unread,
Nov 23, 2016, 7:18:12 AM11/23/16
to Redis DB
Hello zhangkai,

Always prefer using multi-key commands - they are faster.

Your question suggests that you're storing terminals as strings using some serialization. If that is the case, consider using a Hash which is more suitable for this type of data. With Hashes, each key represents a terminal and the fields of that Hash value are the properties and their respective values. Read a specific field, multiple fields or all fields from a Hash using `HGET`, 'HMGET` and `HGETALL`, respectively. To write a value or multiple values call on `HSET` or `HMSET`. In your case, this will save you from the need to read the entire thing, decode it, make a modification, encode it and write it back.

If you stick with serialized strings, Lua is probably the better choice because you can unpack and pack in the script (trivial if you're using a standard like JSON or messagepack). If you use Hashes, Lua may still offer an edge on pipelining because it will also save some of the network traffic's volume.

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+unsubscribe@googlegroups.com.
To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.



--

Itamar Haber | Chief Developer Advocate
Redis Labs ~/redis

Mobile: +972 (54) 567 9692
Email: ita...@redislabs.com
Twitter: @itamarhaber
Skype: itamar.haber

Blog  |  Twitter  |  LinkedIn


Kai Zhang

unread,
Nov 25, 2016, 12:32:06 AM11/25/16
to Redis DB
Hi Itamar Haber,

Thanks for your reply,

before I saw your suggestion,I used protobuffer to serialize the terminals,and I use GET SET with pipeline.to rewrite terminal infos.are GET/SET the most origin way to store to redis? I do not know whether or not use GET/SET with pipeline is a good idea.My code is here can you have a look? maybe the code is not a good usage of redis pipeline.

Thanks,
zhangkai

在 2016年11月23日星期三 UTC+8下午8:18:12,Itamar Haber写道:
Hello zhangkai,

Always prefer using multi-key commands - they are faster.

Your question suggests that you're storing terminals as strings using some serialization. If that is the case, consider using a Hash which is more suitable for this type of data. With Hashes, each key represents a terminal and the fields of that Hash value are the properties and their respective values. Read a specific field, multiple fields or all fields from a Hash using `HGET`, 'HMGET` and `HGETALL`, respectively. To write a value or multiple values call on `HSET` or `HMSET`. In your case, this will save you from the need to read the entire thing, decode it, make a modification, encode it and write it back.

If you stick with serialized strings, Lua is probably the better choice because you can unpack and pack in the script (trivial if you're using a standard like JSON or messagepack). If you use Hashes, Lua may still offer an edge on pipelining because it will also save some of the network traffic's volume.

On Wed, Nov 23, 2016 at 4:25 AM, Kai Zhang <zhangk...@gmail.com> wrote:
Hello all,
     I am a newbie to Redis,My redis store terminal infos such as id, name, status, property etc.There are many terminals will update it's status.But some "fixed“ info will not be modified.So I need to read the terminal info first, then modify the status and key the fixed properties then I will rewrite the redis.What is the best practices for this situation? mget? mset? pipe ? lua script?
many thanks,
zhangkai
2016.11.23

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.

To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.

Itamar Haber

unread,
Nov 25, 2016, 11:13:24 AM11/25/16
to Redis DB
Thanks for asking me to review the code - I'm not a Go person, but the final call to EXEC seems unneeded.

If you stick with protobuf serialization, then GET/SET in pipelines is a good choice.



To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+unsubscribe@googlegroups.com.

To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages