Redis : Basics

Recently I have been playing around with Redis. In particular I have been trying how to integrate Redis with web services in Azure.

Redis is actually more like a data structures server, supporting very interesting data structures, and operations on them.

I am listing down some data structures, and corresponding when using these data structures.

  1. Strings
  2. Lists
  3. Sets
  4. Sorted Sets
    • Useful when fast access to the middle of a large collection of elements is important
  5. Hashes
    • Hashes are maps between string fields and string values, so they are the perfect data type to represent objects.
  6. Bit arrays
  7. Hyper Log Log

 

DECR, DECRBY, DEL, EXISTS, EXPIRE, GET, GETSET, HDEL, HEXISTS, HGET, HGETALL, HINCRBY, HKEYS, HLEN, HMGET, HMSET, HSET, HVALS, INCR, INCRBY, KEYS, LINDEX, LLEN, LPOP, LPUSH,LRANGE, LREM, LSET, LTRIM, MGET, MSET, MSETNX, MULTI, PEXPIRE, RENAME, RENAMENX, RPOP, RPOPLPUSH, RPUSH, SADD, SCARD, SDIFF, SDIFFSTORE, SET, SETEX, SETNX, SINTER, SINTERSTORE, SISMEMBER, SMEMBERS, SMOVE, SORT, SPOP, SRANDMEMBER, SREM, SUNION, SUNIONSTORE, TTL, TYPE, ZADD,ZCARD, ZCOUNT, ZINCRBY, ZRANGE, ZRANGEBYSCORE, ZRANK, ZREM, ZREMRANGEBYSCORE, ZREVRANGE, ZSCORE

 

Code on GitHub:

References:

An Interesting JSON Example

In web services development folks use JSON all the time. However, the JSON format itself is very interesting, in terms of the wide range of semantics (e.g. classes lists, dicts etc) it can represent

Recent I spent some time understanding the format itself.

Example 1:

{“Unixtimestamp”:14593556,”Entities”:[{“Id”:”eid1″},{“Id”:”math”},{“Id”:”computerscience”}],”CategoricalEntries”:[{“Name”:”course”,”Value”:”math”},{“Name”:”major”,”Value”:”computerscience”}],”NumericalEntries”:[{“Name”:”durationspentinmilliseconds”,”Value”:40.0}],”GeoLocations”:[{“Name”:”location”,”Latitude”:”0.34.5N”,”Longitude”:”3.456S”}]}

Example 2:

{“Unixtimestamp”:14593556,”Value”:100.0,”Entities”:{“userid”:”eid1″,”courseid”:”math”,”majorid”:”computerscience”},”CategoricalEntries”:{“course”:”math”,”major”:”computerscience”},”NumericalEntries”:{“durationspentinmilliseconds”:40.0},”GeoLocations”:[{“Latitude”:”0.34.5N”,”Longitude”:”3.456S”}]}

Notice how the “CategoricalEntries” section actually represents different semantics –

  • Example1 : “CategoricalEntries” represents list of objects. The object has two properties explicitly called “Name” and “Value”
  • Example2 : “CategoricalEntries” represents a Dictionary<string, string>

Code: