() {
304 |
305 | @Override
306 | public String action(Jedis jedis) {
307 | return jedis.getSet(key, value);
308 | }
309 | });
310 | }
311 |
312 | /**
313 | * Increment the number stored at key by one. If the key does not exist or
314 | * contains a value of a wrong type, set the key to the value of "0" before
315 | * to perform the increment operation.
316 | *
317 | * INCR commands are limited to 64 bit signed integers.
318 | *
319 | * Note: this is actually a string operation, that is, in Redis there are
320 | * not "integer" types. Simply the string stored at the key is parsed as a
321 | * base 10 64 bit signed integer, incremented, and then converted back as a
322 | * string.
323 | *
324 | * @return Integer reply, this commands will reply with the new value of key
325 | * after the increment.
326 | */
327 | public Long incr(final String key) {
328 | return execute(new JedisAction() {
329 | @Override
330 | public Long action(Jedis jedis) {
331 | return jedis.incr(key);
332 | }
333 | });
334 | }
335 |
336 | public Long incrBy(final String key, final long increment) {
337 | return execute(new JedisAction() {
338 | @Override
339 | public Long action(Jedis jedis) {
340 | return jedis.incrBy(key, increment);
341 | }
342 | });
343 | }
344 |
345 | public Double incrByFloat(final String key, final double increment) {
346 | return execute(new JedisAction() {
347 | @Override
348 | public Double action(Jedis jedis) {
349 | return jedis.incrByFloat(key, increment);
350 | }
351 | });
352 | }
353 |
354 | /**
355 | * Decrement the number stored at key by one. If the key does not exist or
356 | * contains a value of a wrong type, set the key to the value of "0" before
357 | * to perform the decrement operation.
358 | */
359 | public Long decr(final String key) {
360 | return execute(new JedisAction() {
361 | @Override
362 | public Long action(Jedis jedis) {
363 | return jedis.decr(key);
364 | }
365 | });
366 | }
367 |
368 | public Long decrBy(final String key, final long decrement) {
369 | return execute(new JedisAction() {
370 | @Override
371 | public Long action(Jedis jedis) {
372 | return jedis.decrBy(key, decrement);
373 | }
374 | });
375 | }
376 |
377 | // / Hash Actions ///
378 | /**
379 | * If key holds a hash, retrieve the value associated to the specified
380 | * field.
381 | *
382 | * If the field is not found or the key does not exist, a special 'nil'
383 | * value is returned.
384 | */
385 | public String hget(final String key, final String fieldName) {
386 | return execute(new JedisAction() {
387 | @Override
388 | public String action(Jedis jedis) {
389 | return jedis.hget(key, fieldName);
390 | }
391 | });
392 | }
393 |
394 | public List hmget(final String key, final String... fieldsNames) {
395 | return execute(new JedisAction>() {
396 | @Override
397 | public List action(Jedis jedis) {
398 | return jedis.hmget(key, fieldsNames);
399 | }
400 | });
401 | }
402 |
403 | public Map hgetAll(final String key) {
404 | return execute(new JedisAction