Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Next Level Redis With Spring

Next Level Redis With Spring

Introduction to Redis, Object Hash Mapping, Secondary Indexes and how Spring Data helps you build all that.

Christoph Strobl

August 02, 2016
Tweet

More Decks by Christoph Strobl

Other Decks in Programming

Transcript

  1. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Next Level Redis With Spring Christoph Strobl @stroblchristoph
  2. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 2
  3. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 3 Remote Directory Server KeyValue Store Cache Queues Analytics Geo Indexing Session Store Distributed Locks Strings Hashes Lists Sets Sorted Sets HyperLogLog Transactions Pub/Sub Scripting
  4. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 4 DataTypes & Commands
  5. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 5 V A L U E SET GET K E Y STRLEN APPEND GETSET GETRANGE SETRANGE 3 . 1 4 1 INCR INCRBY DECR DECRBY INCRBYFLOAT DECRBYFLOAT SETNX Strings
  6. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Arya 6 S T A R K LPUSH LPOP RPUSH RPOP LLEN LSET LGET LINSERT LRANGE LREM Lists Jon Bran
  7. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 7 Sets L A N N I S T E R Tyrion Jaime Cersei SADD SPOP SREM SCARD SMEMBERS SISMEMBER
  8. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 8 Hashes D A E N E R Y S firstname lastname gender daenerys targaryen female HSET HGET HMSET HMGET HVALS HKEYS HDEL HLEN HGETALL
  9. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 9 multi/exec MULTI EXEC SET key value GET key QUEUED QUEUED [OK, value] DISCARD OK
  10. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 10 Single Node / HA / Cluster
  11. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 11
  12. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 12
  13. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 13 S S S
  14. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 14 Slots:
 0 - 8192 Slots:
 8993 - 16384
  15. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 15 DEMO
 cluster commands
  16. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 16 Object Hash Mapping
  17. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 17 class Person { String id; String firstname; String lastname; Address address; } SET {person}:123 { "id":123, "firstname":"jon", "lastname":"snow", "address": { "country":"the north" } } HMSET {person}:123 _class org.example.Person id 123 firstname jon lastname snow address.country the north GET {person}:123 HGETALL {person}:123 HGET {person}:123 id lastname HSET {person}:123 lastname doe HEXISTS {person}:123 age ...
  18. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 18 DEMO
 Object Hash Mapping
  19. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 19 Secondary Indexes
  20. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 20 class Person { String id; String firstname; String lastname; Address address; } HMSET {person}:123 _class org.example.Person id 123 firstname jon lastname snow address.country the north SADD {person}:firstname:jon 123 SADD {person}:lastname:snow 123 123 {person}:firstname:jon 101 567 721 {person}:lastname:snow 122 133 987 SINTER {person}:firstname:jon {person}:lastname:snow SUNION {person}:firstname:jon {person}:lastname:snow
  21. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 21 @RedisHash("{person}") class Person { @Id String id; @Indexed String firstname; @Indexed String lastname; Address address; } HMSET {person}:123 id 123 firstname john ... SADD {person}:firstname:john 123 SADD {person}:lastname:snow 123 SINTER {person}:firstname:jon {person}:lastname:snow interface PersonRepository extends CrudRepository<Person, String> { " " } repo.save(new Person("123", "john", "snow")); repo.update( newPartialUpdate("123", Person.class) .set("firstname", "jon")); HSET {person}:123 firstname jon SREM {person}:firstname:john 123 SADD {person}:firstname:jon 123 List<Person> findByFirstnameAndLastname(String firstname, String lastname); repo.findByFirstnameAndLastname("jon", "snow"); HGETALL {person}:123
  22. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 22 DEMO
 Redis Repositories
  23. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 23 Expire Commands Custom Conversions SpEL based indexing References
  24. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 24 CC BY 2.0 
 https://www.flickr.com/photos/crystalflickr/2317183342
  25. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 25 Reactive Data Access Geo Indexes
  26. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 26 @RedisHash("{person}") class Person { @Id String id; Address address; } HMSET {person}:123 id 123 firstname jon ... GEOADD {person}:address:location 13.361389 39.115556 123 GEORADIUS {person}:address:location 15.0 37.0 200.0 km interface PersonRepository extends CrudRepository<Person, String> { " " } repo.save(new Person("123", "jon", "snow") .withAddress( new Address("winterfell", new Point(13.361389D, 38.115556D))) ); List<Person> findByAddressLocationNear(Point location, Distance distance); repo.findByAddressLocationNear( new Point(15D, 37D), new Distance(200, Metrics.KILOMETERS)); HGETALL {person}:123 class Address { String city; @GeoIndexed Point location; }
  27. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 27
  28. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Related Sessions • Wed, 3rd, August, 2016 • 2:00 pm – John Blum, Mark Paluch
 Outlook: Spring Data Cassandra 1.5 " • Thu, 4th, August, 2016 • 9:00 am – John Blum, Luke Shannon 
 Spring Data and In-Memory Data Management in Action " • Thu, 4th, August, 2016 • 11:45 am – Viktor Gamov, Neil Stevenson 
 Spring Data Hazelcast: Fluently Accessing Distributed Repositories 28
  29. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Learn More. Stay Connected. Follow us @SpringData @springcentral spring.io/blog @pivotal pivotal.io/blog @pivotalcf http://engineering.pivotal.io Talk to us spring-projects/spring-data
  30. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Safe Harbor Statement • The following is intended to outline the general direction of Pivotal's offerings. It is intended for information purposes only and may not be incorporated into any contract. Any information regarding pre-release of Pivotal offerings, future updates or other planned modifications is subject to ongoing evaluation by Pivotal and is subject to change. This information is provided without warranty or any kind, express or implied, and is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions regarding Pivotal's offerings. These purchasing decisions should only be based on features currently available. The development, release, and timing of any features or functionality described for Pivotal's offerings in this presentation remain at the sole discretion of Pivotal. Pivotal has no obligation to update forward looking information in this presentation. 30