Explanation of small Redis snippet -
i'm referring great answer given @sripathi krishnan question asked here on so: redis cache
i'm trying learn how use redis , research brought me question on so.
can please explain reason these 2 lines in code because i'm still finding difficult understand usefulness in code sripathi gave in answer.
$ hincrby unique_ids question 1 $ hincrby unique_ids answer 1  i know creates hash 'unique_ids' key fields 'question' , 'answer' first initialised 0 increased 1. apart this, don't see link of unique_ids key flow i'm not sure if noob mind missing something.
these commands way generate synthetic primary keys.
in sri's example, people can add questions , answers in system. these entities need referenced, need identified unique keys. may imagine using kind of uuid mechanism this, using numeric keys simpler.
the unique_ids convenient container store next available keys of objects stored in system. add new question, increment question field of unique_ids (atomic operation redis) , use returned value key of new question. guarantees new questions have different key value.
in relational data stores, such feature provided sequences (oracle, postgresql) or autoincrement primary keys (mysql).
Comments
Post a Comment