Files

62 lines
1.3 KiB
Plaintext

# @RedisHash and CrudRepository: the keys Spring Data Redis creates
--- Save two people ---
people.save(new Person("1", "Ankur", "Mhatre", 40))
people.save(new Person("2", "Asha", "Mhatre", 38))
--- Every key it created ---
$ redis-cli -p 6390 KEYS '*' | sort
person
person:1
person:1:idx
person:2
person:2:idx
person:lastName:Mhatre
--- The entity is a hash ---
$ redis-cli -p 6390 --no-raw TYPE person:1
hash
$ redis-cli -p 6390 --no-raw HGETALL person:1
1) "_class"
2) "com.ankurm.redis.hash.Person"
3) "age"
4) "40"
5) "firstName"
6) "Ankur"
7) "id"
8) "1"
9) "lastName"
10) "Mhatre"
--- The keyspace is a set of ids ---
$ redis-cli -p 6390 SMEMBERS person | sort
1
2
--- The @Indexed field is a set per value ---
$ redis-cli -p 6390 SMEMBERS person:lastName:Mhatre | sort
1
2
--- And each entity remembers which index sets it is in ---
$ redis-cli -p 6390 SMEMBERS person:1:idx | sort
person:lastName:Mhatre
--- What the repository returns ---
people.findById("1") = Person[id=1, Ankur Mhatre, age=40]
people.count() = 2
people.findByLastName("Mhatre") = 2 results
--- Delete one, and look again ---
people.deleteById("1")
$ redis-cli -p 6390 KEYS '*' | sort
person
person:2
person:2:idx
person:lastName:Mhatre
$ redis-cli -p 6390 SMEMBERS person:lastName:Mhatre | sort
2
$ redis-cli -p 6390 SMEMBERS person | sort
2