@@ -243,7 +243,7 @@ class StrictRedis(object):
243
243
'PING' : lambda r : nativestr (r ) == 'PONG' ,
244
244
'RANDOMKEY' : lambda r : r and r or None ,
245
245
'SCRIPT' : parse_script ,
246
- 'SET' : lambda r : r and nativestr (r ) == 'OK' or None ,
246
+ 'SET' : lambda r : r and nativestr (r ) == 'OK' ,
247
247
'TIME' : lambda x : (int (x [0 ]), int (x [1 ]))
248
248
}
249
249
)
@@ -430,22 +430,10 @@ def dbsize(self):
430
430
"Returns the number of keys in the current database"
431
431
return self .execute_command ('DBSIZE' )
432
432
433
- def time (self ):
434
- """
435
- Returns the server time as a 2-item tuple of ints:
436
- (seconds since epoch, microseconds into this second).
437
- """
438
- return self .execute_command ('TIME' )
439
-
440
433
def debug_object (self , key ):
441
434
"Returns version specific metainformation about a give key"
442
435
return self .execute_command ('DEBUG' , 'OBJECT' , key )
443
436
444
- def delete (self , * names ):
445
- "Delete one or more keys specified by ``names``"
446
- return self .execute_command ('DEL' , * names )
447
- __delitem__ = delete
448
-
449
437
def echo (self , value ):
450
438
"Echo the string back from the server"
451
439
return self .execute_command ('ECHO' , value )
@@ -514,6 +502,13 @@ def slaveof(self, host=None, port=None):
514
502
return self .execute_command ("SLAVEOF" , "NO" , "ONE" )
515
503
return self .execute_command ("SLAVEOF" , host , port )
516
504
505
+ def time (self ):
506
+ """
507
+ Returns the server time as a 2-item tuple of ints:
508
+ (seconds since epoch, microseconds into this second).
509
+ """
510
+ return self .execute_command ('TIME' )
511
+
517
512
#### BASIC KEY COMMANDS ####
518
513
def append (self , key , value ):
519
514
"""
@@ -523,13 +518,6 @@ def append(self, key, value):
523
518
"""
524
519
return self .execute_command ('APPEND' , key , value )
525
520
526
- def getrange (self , key , start , end ):
527
- """
528
- Returns the substring of the string value stored at ``key``,
529
- determined by the offsets ``start`` and ``end`` (both are inclusive)
530
- """
531
- return self .execute_command ('GETRANGE' , key , start , end )
532
-
533
521
def bitcount (self , key , start = None , end = None ):
534
522
"""
535
523
Returns the count of set bits in the value of ``key``. Optional
@@ -558,6 +546,11 @@ def decr(self, name, amount=1):
558
546
"""
559
547
return self .execute_command ('DECRBY' , name , amount )
560
548
549
+ def delete (self , * names ):
550
+ "Delete one or more keys specified by ``names``"
551
+ return self .execute_command ('DEL' , * names )
552
+ __delitem__ = delete
553
+
561
554
def exists (self , name ):
562
555
"Returns a boolean indicating whether key ``name`` exists"
563
556
return self .execute_command ('EXISTS' , name )
@@ -601,6 +594,13 @@ def getbit(self, name, offset):
601
594
"Returns a boolean indicating the value of ``offset`` in ``name``"
602
595
return self .execute_command ('GETBIT' , name , offset )
603
596
597
+ def getrange (self , key , start , end ):
598
+ """
599
+ Returns the substring of the string value stored at ``key``,
600
+ determined by the offsets ``start`` and ``end`` (both are inclusive)
601
+ """
602
+ return self .execute_command ('GETRANGE' , key , start , end )
603
+
604
604
def getset (self , name , value ):
605
605
"""
606
606
Set the value at key ``name`` to ``value`` if key doesn't exist
@@ -643,20 +643,33 @@ def mget(self, keys, *args):
643
643
args = list_or_args (keys , args )
644
644
return self .execute_command ('MGET' , * args )
645
645
646
- def mset (self , mapping ):
647
- "Sets each key in the ``mapping`` dict to its corresponding value"
646
+ def mset (self , * args , ** kwargs ):
647
+ """
648
+ Sets key/values based on a mapping. Mapping can be supplied as a single
649
+ dictionary argument or as kwargs.
650
+ """
651
+ if args :
652
+ if len (args ) != 1 or not isinstance (args [0 ], dict ):
653
+ raise RedisError ('MSET requires **kwargs or a single dict arg' )
654
+ kwargs .update (args [0 ])
648
655
items = []
649
- for pair in iteritems (mapping ):
656
+ for pair in iteritems (kwargs ):
650
657
items .extend (pair )
651
658
return self .execute_command ('MSET' , * items )
652
659
653
- def msetnx (self , mapping ):
660
+ def msetnx (self , * args , ** kwargs ):
654
661
"""
655
- Sets each key in the ``mapping`` dict to its corresponding value if
656
- none of the keys are already set
662
+ Sets key/values based on a mapping if none of the keys are already set.
663
+ Mapping can be supplied as a single dictionary argument or as kwargs.
664
+ Returns a boolean indicating if the operation was successful.
657
665
"""
666
+ if args :
667
+ if len (args ) != 1 or not isinstance (args [0 ], dict ):
668
+ raise RedisError ('MSETNX requires **kwargs or a single '
669
+ 'dict arg' )
670
+ kwargs .update (args [0 ])
658
671
items = []
659
- for pair in iteritems (mapping ):
672
+ for pair in iteritems (kwargs ):
660
673
items .extend (pair )
661
674
return self .execute_command ('MSETNX' , * items )
662
675
0 commit comments