redis 127.0.0.1:6379> incr book_id #用book_id这个key保存book表的id,每次要获得一个新的 #book_id用incr命令自增取得 (integer) 1 #incr命令返回1,则用key为book:1的hash来保存一个book对象,对象属性为hash的field redis 127.0.0.1:6379> hset book:1 name "The Ruby Programming Language" (integer) 1 redis 127.0.0.1:6379> hset book:1 author "Mark Pilgrim" (integer) 1 redis 127.0.0.1:6379> hgetall book:1 #用hgetall命令测试一个,返回hash的所有属性和值 1) "name" 2) "The Ruby Programming Language" 3) "author" 4) "Mark Pilgrim" redis 127.0.0.1:6379> incr book_id #创建第2个book对象,先incr一个book_id获得新book的id (integer) 2 redis 127.0.0.1:6379> hset book:2 name "Ruby on rail" (integer) 1 redis 127.0.0.1:6379> hset book:2 author "David Flanagan" (integer) 1 redis 127.0.0.1:6379> hgetall book:2 1) "name" 2) "Ruby on rail" 3) "author" 4) "David Flanagan" redis 127.0.0.1:6379> incr book_id (integer) 3 redis 127.0.0.1:6379> hset book:3 name "Programming Erlang" (integer) 1 redis 127.0.0.1:6379> hset book:3 author "Joe Armstrong" (integer) 1 redis 127.0.0.1:6379> hgetall book:3 1) "name" 2) "Programming Erlang" 3) "author" 4) "Joe Armstrong" |