Practice key-value commands and understand atomic counter operations.

Before starting: Keys, values and a command-line client.

Practice project: Extend the examples into a small Redis study demo. Explain the setup, one normal case and one failure or boundary case.

Start here: concepts and guided practice

  1. Redis: build a counter

    Redis stores values under keys. INCR increments an integer stored as a string. One INCR command is atomic; a sequence of independent commands is not automatically one transaction.

    Disposable local Redis instance and redis-cli. Use the study: prefix only for practice keys.

    SET study:visits 0
    INCR study:visits
    INCR study:visits
    GET study:visits
    Check the output
    OK, then 1, then 2; GET returns the string "2".

    Reset this practice key to 10 and predict the next INCR result.

  2. Redis: reject a non-integer counter

    A counter value must represent an integer within Redis integer limits. INCR does not turn arbitrary text into a number. An invalid value produces an error.

    Disposable local Redis instance and redis-cli. Use the study: prefix only for practice keys.

    SET study:visits hello
    INCR study:visits
    GET study:visits
    Check the output
    INCR reports that the value is not an integer or is out of range. GET still returns hello.

    Restore study:visits to 0 and retry INCR.

Open the Redis learning path on DevStudyHub · Play coding games on this blog

logoblog

No comments:

Post a Comment

Please do not enter any spam link in the comment box.