Redis with spring data key value

2,979 views

Published on

Published in: Technology, Lifestyle
  • Be the first to comment

Redis with spring data key value

  1. 1. Redis with Spring Data KeyValue Sean@Weaveus May 2011Monday, May 9, 2011 1
  2. 2. • http://redis.io/ • open source • by CitrusByte • sponsored by VMWareMonday, May 9, 2011 2
  3. 3. • key/value store • in memory/persistence • Values • String, List, Set, Binary, ... • command by values • speed - faster • replication - master/slave asyncMonday, May 9, 2011 3
  4. 4. Monday, May 9, 2011 4
  5. 5. Redis Command Client // String Type Value sean@ubuntu:~$ redis-cli set mykey "my binary safe value" OK sean@ubuntu:~$ redis-cli get mykey my binary safe value sean@ubuntu:~$ redis-cli set mykey 100 OK sean@ubuntu:~$ redis-cli incr mykey (integer) 101 sean@ubuntu:~$ redis-cli incrby mykey 10 (integer) 111Monday, May 9, 2011 5
  6. 6. List sean@ubuntu:~$ redis-cli rpush messages "hello" OK sean@ubuntu:~$ redis-cli rpush messages "fine" OK sean@ubuntu:~$ redis-cli rpush messages "nosql" OK sean@ubuntu:~$ redis-cli lrange messages 0 2 1. hello 2. fine 3. nosql sean@ubuntu:~$ redis-cli lrange messages 0 -1 // first to end 1. hello 2. fine 3. nosqlMonday, May 9, 2011 6
  7. 7. List with ID $ redis-cli incr next.news.id (integer) 1 $ redis-cli set news:1:title "Redis is simple" OK $ redis-cli set news:1:url "http://code.google.com/p/redis" OK $ redis-cli lpush submitted.news 1 OK • generate unique ID • a new actual data • push new ID of the actual dataMonday, May 9, 2011 7
  8. 8. Set sean@ubuntu:~$ redis-cli sadd news:1000:tags 1 (integer) 1 sean@ubuntu:~$ redis-cli sadd news:1000:tags 100 (integer) 1 sean@ubuntu:~$ redis-cli sadd news:1000:tags 777 (integer) 1 sean@ubuntu:~$ redis-cli sadd tags:1:objects 1000 (integer) 1 sean@ubuntu:~$ redis-cli sadd tags:100:objects 1000 (integer) 1 sean@ubuntu:~$ redis-cli sadd tags:777:objects 1000 (integer) 1 sean@ubuntu:~$ redis-cli smembers news:1000:tags 1. 777 2. 100 3. 1 sean@ubuntu:~$ redis-cli sismember news:1000:tags 5 (integer) 0Monday, May 9, 2011 8
  9. 9. Set Selection/Union sean@ubuntu:~$ redis-cli sadd news:1001:tags 888 (integer) 1 sean@ubuntu:~$ redis-cli sadd tags:888:objects 1001 (integer) 1 sean@ubuntu:~$ redis-cli sinter tags:777:objects tags:888:objects (empty list or set) sean@ubuntu:~$ redis-cli sunion tags:777:objects tags:888:objects 1. 1000 2. 1001Monday, May 9, 2011 9
  10. 10. Sorted Set sean@ubuntu:~$ redis-cli zadd hackers 1940 "Alan Kay" (integer) 1 sean@ubuntu:~$ redis-cli zadd hackers 1969 "Linus" (integer) 1 sean@ubuntu:~$ redis-cli zrange hackers 0 -1 1. Alan Kay 2. Linus sean@ubuntu:~$ redis-cli zrangetbyscore hackers 1900 1950 1. Alan KayMonday, May 9, 2011 10
  11. 11. with Java import redis.clients.jedis.Jedis Jedis jedis = new Jedis("ubuntu.sean.me") println jedis.lrange("messages", 0, -1) // Result [hello, fine, nosql] • JDBC-Redis • Jedis library - PopularMonday, May 9, 2011 11
  12. 12. with Spring <<interface>> @Autowired Redis Operations Bean Redis Template Bean Redis DriverMonday, May 9, 2011 12
  13. 13. BeansMonday, May 9, 2011 13

×