@@ -381,13 +381,13 @@ REDIS_PW=
381
381
- Normally a hash stores data as key value pair.
382
382
- A sorted set stores as members and score.
383
383
384
- * but a SCORE data structure in redis sorts using the members of the set, sorted set or list!
384
+ * but a ` SCORE` data structure in redis sorts using the members of the ` set`, ` sorted set` or ` list` !
385
385
386
386
- first create some sets and sorted sets:
387
387
```bash
388
388
HSET books:good title 'Good Book' year 1950
389
389
HSET books:bad title 'Bad Book' year 1930
390
- HSET books:ok title 'Ok Book' year 1940
390
+ HSET books:ok title 'Ok Book' year 1940
391
391
392
392
ZADD books:likes 999 good
393
393
ZADD books:likes 0 bad
@@ -422,20 +422,111 @@ then apply ->
422
422
- create a volatile set with key value structure like:
423
423
``` bash
424
424
good - 1950
425
- bad - 1920
426
- ok - 1960
425
+ bad - 1930
426
+ ok - 1940
427
427
```
428
428
- BY means sort the set by descending order like:
429
429
``` bash
430
- bad - 1920
430
+ bad - 1930
431
+ ok - 1940
431
432
good - 1950
432
- ok - 1960
433
433
```
434
434
response from redis:
435
435
``` bash
436
436
[
437
437
" bad" ,
438
+ " ok" ,
439
+ " good"
440
+ ]
441
+ ```
442
+
443
+ - ` SORT books:likes BY books:*->year GET books:*->title ` :
444
+ * breakdown of the command:
445
+ - first replace the * with the member from the sorted set : books: good
446
+ - scan redis for the key books: good
447
+ - if the key exists then find the value with the year: books: good has year 1950 in it.
448
+ - create a volatile set with key value structure like:
449
+ ``` bash
450
+ good - 1950
451
+ bad - 1930
452
+ ok - 1940
453
+ ```
454
+ - BY means sort the set by descending order like:
455
+ ``` bash
456
+ bad - 1930
457
+ ok - 1940
458
+ good - 1950
459
+ ```
460
+
461
+ - ` GET books:*->title ` :
462
+ - again scan redis and find the books: good and return the title of the book
463
+ - use sorting criteria from BY year
464
+
465
+ response from redis:
466
+ ``` bash
467
+ [
468
+ " Bad Book" ,
469
+ " Ok Book" ,
470
+ " Good Book"
471
+ ]
472
+ ```
473
+ * More examples:
474
+ ``` bash
475
+ SORT books:likes BY books:* -> year
476
+ GET books:* -> title
477
+ GET books:* -> year
478
+ ```
479
+ - response:
480
+ ``` bash
481
+ [
482
+ " Bad Book" ,
483
+ " 1930" ,
484
+ " Ok Book" ,
485
+ " 1940" ,
486
+ " Good Book" ,
487
+ " 1950"
488
+ ]
489
+ ```
490
+
491
+ * in here # means also give the name of the member with associated record
492
+ ``` bash
493
+ SORT books:likes BY books:* -> year
494
+ GET #
495
+ GET books:* -> title
496
+ GET books:* -> year
497
+ ```
498
+ - response:
499
+ ``` bash
500
+ [
501
+ " bad" ,
502
+ " Bad Book" ,
503
+ " 1930" ,
504
+ " ok" ,
505
+ " Ok Book" ,
506
+ " 1940" ,
438
507
" good" ,
439
- " ok"
508
+ " Good Book" ,
509
+ " 1950"
440
510
]
441
- ```
511
+ ```
512
+
513
+ * in here ` nosort ` means give the associated record but not based on any sorting criteria:
514
+ ``` bash
515
+ SORT books:likes BY nosort
516
+ GET #
517
+ GET books:* -> title
518
+ GET books:* -> year
519
+ ```
520
+ - response:
521
+ ``` bash
522
+ [
523
+ " bad" ,
524
+ " Bad Book" ,
525
+ " 1930" ,
526
+ " ok" ,
527
+ " Ok Book" ,
528
+ " 1940" ,
529
+ " good" ,
530
+ " Good Book" ,
531
+ " 1950"
532
+ ]
0 commit comments