Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

237 lignes
7.1 KiB

  1. const client = global.redisClient;
  2. if (client) {
  3. const { promisify } = require('util');
  4. const commands = {};
  5. [
  6. 'append', 'decr', 'decrby', 'del', 'exists', 'get', 'getset', 'incr', 'incrby',
  7. 'mget', 'set', 'setex', 'setnx', 'strlen', 'lindex', 'linsert', 'llen', 'lpop',
  8. 'lpos', 'lpush', 'lpushx', 'lrange', 'lrem', 'lset', 'ltrim', 'rpop', 'rpush',
  9. 'rpushx', 'copy', 'del', 'expire', 'expireat', 'keys', 'persist', 'pexpire',
  10. 'pexpireat', 'pttl', 'randomkey', 'rename', 'renamenx', 'touch', 'ttl', 'type',
  11. 'unlink'
  12. ].forEach(command => {
  13. commands[command] = promisify(client[command]).bind(client);
  14. });
  15. exports.append = function(options) {
  16. options = this.parse(options);
  17. return commands.append(options.key, options.value);
  18. };
  19. exports.decr = function(options) {
  20. options = this.parse(options);
  21. return commands.decr(options.key);
  22. };
  23. exports.decrby = function(options) {
  24. options = this.parse(options);
  25. return commands.decrby(options.key, options.decrement);
  26. };
  27. exports.del = function(options) {
  28. options = this.parse(options);
  29. return commands.del(options.key);
  30. };
  31. exports.exists = function(options) {
  32. options = this.parse(options);
  33. return commands.exists(options.key);
  34. };
  35. exports.get = function(options) {
  36. options = this.parse(options);
  37. return commands.get(options.key);
  38. };
  39. exports.getset = function(options) {
  40. options = this.parse(options);
  41. return commands.getset(options.key, options.value);
  42. };
  43. exports.incr = function(options) {
  44. options = this.parse(options);
  45. return commands.incr(options.key);
  46. };
  47. exports.incrby = function(options) {
  48. options = this.parse(options);
  49. return commands.incrby(options.key, options.increment);
  50. };
  51. exports.mget = function(options) {
  52. options = this.parse(options);
  53. return commands.mget(options.keys);
  54. };
  55. exports.set = function(options) {
  56. options = this.parse(options);
  57. return commands.set(options.key, options.value);
  58. };
  59. exports.setex = function(options) {
  60. options = this.parse(options);
  61. return commands.setex(options.key, options.seconds, options.value);
  62. };
  63. exports.setnx = function(options) {
  64. options = this.parse(options);
  65. return commands.setnx(options.key, options.value);
  66. };
  67. exports.strlen = function(options) {
  68. options = this.parse(options);
  69. return commands.strlen(options.key);
  70. };
  71. exports.lindex = function(options) {
  72. options = this.parse(options);
  73. return commands.lindex(options.key, options.index);
  74. };
  75. exports.linsert = function(options) {
  76. options = this.parse(options); // position: BEFORE|AFTER
  77. return commands.linsert(options.key, options.position, options.pivot, options.element);
  78. };
  79. exports.llen = function(options) {
  80. options = this.parse(options);
  81. return commands.llen(options.key);
  82. };
  83. exports.lpop = function(options) {
  84. options = this.parse(options);
  85. return commands.lpop(options.key, options.count);
  86. };
  87. exports.lpos = function(options) {
  88. options = this.parse(options);
  89. return commands.lpos(options.key, options.element);
  90. };
  91. exports.lpush = function(options) {
  92. options = this.parse(options);
  93. return commands.lpush(options.key, options.element);
  94. };
  95. exports.lpushx = function(options) {
  96. options = this.parse(options);
  97. return commands.lpushx(options.key, options.element);
  98. };
  99. exports.lrange = function(options) {
  100. options = this.parse(options);
  101. return commands.lrange(options.key, options.start, options.stop);
  102. };
  103. exports.lrem = function(options) {
  104. options = this.parse(options);
  105. return commands.lrem(options.key, options.count, options.element);
  106. };
  107. exports.lset = function(options) {
  108. options = this.parse(options);
  109. return commands.lset(options.key, options.index, options.element);
  110. };
  111. exports.ltrim = function(options) {
  112. options = this.parse(options);
  113. return commands.ltrim(options.key, options.start, options.stop);
  114. };
  115. exports.rpop = function(options) {
  116. options = this.parse(options);
  117. return commands.rpop(options.key, options.count);
  118. };
  119. exports.rpush = function(options) {
  120. options = this.parse(options);
  121. return commands.rpush(options.key, options.element);
  122. };
  123. exports.rpushx = function(options) {
  124. options = this.parse(options);
  125. return commands.rpushx(options.key, options.element);
  126. };
  127. exports.copy = function(options) {
  128. options = this.parse(options);
  129. return commands.copy(options.source, options.destination);
  130. };
  131. exports.del = function(options) {
  132. options = this.parse(options);
  133. return commands.del(options.key);
  134. };
  135. exports.expire = function(options) {
  136. options = this.parse(options);
  137. return commands.expire(options.key, options.seconds);
  138. };
  139. exports.expireat = function(options) {
  140. options = this.parse(options);
  141. return commands.expireat(options.key, options.timestamp);
  142. };
  143. exports.keys = function(options) {
  144. options = this.parse(options);
  145. return commands.keys(options.pattern);
  146. };
  147. exports.persist = function(options) {
  148. options = this.parse(options);
  149. return commands.persist(options.key);
  150. };
  151. exports.pexpire = function(options) {
  152. options = this.parse(options);
  153. return commands.pexpire(options.key, options.milliseconds);
  154. };
  155. exports.pexpireat = function(options) {
  156. options = this.parse(options);
  157. return commands.pexpireat(options.key, options.mstimestamp)
  158. };
  159. exports.pttl = function(options) {
  160. options = this.parse(options);
  161. return commands.pttl(options.key);
  162. };
  163. exports.randomkey = function(options) {
  164. options = this.parse(options);
  165. return commands.randomkey();
  166. };
  167. exports.rename = function(options) {
  168. options = this.parse(options);
  169. return commands.rename(options.key, options.newkey);
  170. };
  171. exports.renamenx = function(options) {
  172. options = this.parse(options);
  173. return commands.renamenx(options.key, options.newkey);
  174. };
  175. exports.touch = function(options) {
  176. options = this.parse(options);
  177. return commands.touch(options.key);
  178. };
  179. exports.ttl = function(options) {
  180. options = this.parse(options);
  181. return commands.ttl(options.key);
  182. };
  183. exports.type = function(options) {
  184. options = this.parse(options);
  185. return commands.type(options.key);
  186. };
  187. exports.unlink = function(options) {
  188. options = this.parse(options);
  189. return commands.unlink(options.key);
  190. };
  191. }