Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. ----------------------------
  2. # Overview of redis commands
  3. ----------------------------
  4.  
  5. SET server:name "fido"
  6.  
  7. GET server:name => "fido"
  8.  
  9.  
  10. SET connections 10
  11. INCR connections => 11
  12. INCR connections => 12
  13. DEL connections
  14. INCR connections => 1
  15.  
  16.  
  17. SETNX key value (set key if not exist)
  18.  
  19. SET resource:lock "Redis Demo"
  20. EXPIRE resource:lock 120
  21.  
  22. TTL resource:lock => 113
  23. // after 113s
  24. TTL resource:lock => -2
  25.  
  26. # TTL <something>
  27. => -2 (means the key does not exist anymore)
  28. => -1 (never will expire)
  29.  
  30. RPUSH friends "Alice" (puts at the end of list -- to the right)
  31. LPUSH friends "Sam" (puts at the begining of list -- to the left)
  32.  
  33. LRANGE friends 0 -1 => 1) "Sam", 2) "Alice", 3) "Bob"
  34. LRANGE friends 0 1 => 1) "Sam", 2) "Alice"
  35. LRANGE friends 1 2 => 1) "Alice", 2) "Bob"
  36.  
  37. LRANGE friends 0 -1
  38.  
  39. LLEN friends => 3 (returns the current length of the list)
  40.  
  41. LPOP friends => "Sam" (removes the first element from the list)
  42.  
  43. RPOP friends => "Bob" (removes the last element of the list)
  44.  
  45. SADD douglas "name" (Adds value "name" to the set "douglas")
  46. SADD douglas "website"
  47. SADD douglas "city"
  48.  
  49. > SMEMBERS douglas
  50. 1) "website"
  51. 2) "city"
  52. 3) "name"
  53.  
  54. > SREM douglas city
  55. 1) "website"
  56. 2) "name"
  57.  
  58. SISMEMBER key member
  59. SISMEMBER douglas website => 1 (if element is a member of the set)
  60. SISMEMBER douglas city => 0 (if the element is not a member of the set or if the key does not exist)
  61.  
  62. SUNION key1 key2 ... keyN (union result from the keys passed)
  63.  
  64. > smembers douglas
  65.  
  66. 1) "website"
  67. 2) "name"
  68.  
  69. > smembers maria
  70.  
  71. 1) "endereco"
  72. 2) "nome"
  73. 3) "telefone"
  74.  
  75. > sunion douglas maria
  76.  
  77. 1) "endereco"
  78. 2) "nome"
  79. 3) "name"
  80. 4) "website"
  81. 5) "telefone"
  82.  
  83. ZADD key score something (sorted set associated with a score)
  84.  
  85. ZADD hackers 1940 "Alan Kay"
  86. ZADD hackers 1906 "Grace Hopper"
  87. ZADD hackers 1953 "Richard Stallman"
  88. ZADD hackers 1965 "Yukihiro Matsumoto"
  89. ZADD hackers 1916 "Claude Shannon"
  90. ZADD hackers 1969 "Linus Torvalds"
  91. ZADD hackers 1957 "Sophie Wilson"
  92. ZADD hackers 1912 "Alan Turing"
  93.  
  94. > ZRANGE hackers 0 -1
  95.  
  96. 1) "Grace Hopper"
  97. 2) "Alan Turing"
  98. 3) "Claude Shannon"
  99. 4) "Alan Kay"
  100. 5) "Richard Stallman"
  101. 6) "Sophie Wilson"
  102. 7) "Yukihiro Matsumoto"
  103. 8) "Linus Torvalds"
  104.  
  105. HSET table:id field value (Hashes are maps btw string fields and string values)
  106.  
  107. HSET user:1000 name "John Smith"
  108. HSET user:1000 email "john.smith@example.com"
  109. HSET user:1000 password "s3cret"
  110.  
  111. > HGET user:1000 name => "John Smith"
  112.  
  113. > HGETALL user:1000
  114. 1) "name"
  115. 2) "John Smith"
  116. 3) "email"
  117. 4) "john.smith@example.com"
  118. 5) "password"
  119. 6) "s3cret"
  120.  
  121. HMSET user:1001 name "Mary Jones" password "hidden" email "mjones@example.com" (setting multiple fields at once)
  122.  
  123. HSET user:1000 visits 10
  124. HINCRBY user:1000 visits 1 => 11
  125. HINCRBY user:1000 visits 10 => 21
  126. HDEL user:1000 visits
  127. HINCRBY user:1000 visits 1 => 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement