Skip to content

Instantly share code, notes, and snippets.

@deepak
Created September 28, 2010 11:42
Show Gist options
  • Save deepak/600842 to your computer and use it in GitHub Desktop.
Save deepak/600842 to your computer and use it in GitHub Desktop.
how to name keys in redis for keyvalue stores
# how to name keys in redis for keyvalue stores
http://code.google.com/p/redis/wiki/TwitterAlikeExample
http://rediscookbook.org/introduction_to_storing_objects.html
http://www.slideshare.net/playnicelyapp/redis-schema-design-for-playnicely-redis-london-meetup
antirez has a book about keyvalue design in the pipeline
http://code.google.com/p/redis/wiki/IntroductionToRedisDataTypes
schema:
<namespace>:<globalObject>
<model>:<id>
<model>:<id>:<attribute>
<model>:<id>:<multi.word.field>
eg:
# <namespace>:<globalObject>
# global is a special model used as a namespace
redis.setnx("global:nextUserId", 0)
redis.incr("global:nextUserId")
redis.setnx("global:nextPostId", 0)
# <model>:<id>:<attribute>
# the attribute can contain string or an array
redis.set("user:5:name", "deepak")
redis.set("user:5:email", "[email protected]")
# a common pattern is to store a serialized array for arbitrary attributes
redis.set("user:5:attributes", {:age => 25, :nick => "deep", :favs => ["github", "ruby"]}.to_json)
# <model>:<id>
# serialization can be json, yaml or homegrown :-)
redis.set("post:1", "5|02122010|hello anyone home")
# <model>:<id>:<multi.word.field>
# dots for multi-words fields
redis.set("comment:1234:reply.to", "[email protected]")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment