@@ -1862,100 +1862,3 @@ def __call__(self, keys=[], args=[], client=None):
18621862 # Overwrite the sha just in case there was a discrepancy.
18631863 self .sha = client .script_load (self .script )
18641864 return client .evalsha (self .sha , len (keys ), * args )
1865-
1866-
1867- class BitFieldOperation :
1868- """
1869- Command builder for BITFIELD commands.
1870- """
1871- def __init__ (self , client , key , default_overflow = None ):
1872- self .client = client
1873- self .key = key
1874- self ._default_overflow = default_overflow
1875- self .reset ()
1876-
1877- def reset (self ):
1878- """
1879- Reset the state of the instance to when it was constructed
1880- """
1881- self .operations = []
1882- self ._last_overflow = 'WRAP'
1883- self .overflow (self ._default_overflow or self ._last_overflow )
1884-
1885- def overflow (self , overflow ):
1886- """
1887- Update the overflow algorithm of successive INCRBY operations
1888- :param overflow: Overflow algorithm, one of WRAP, SAT, FAIL. See the
1889- Redis docs for descriptions of these algorithmsself.
1890- :returns: a :py:class:`BitFieldOperation` instance.
1891- """
1892- overflow = overflow .upper ()
1893- if overflow != self ._last_overflow :
1894- self ._last_overflow = overflow
1895- self .operations .append (('OVERFLOW' , overflow ))
1896- return self
1897-
1898- def incrby (self , fmt , offset , increment , overflow = None ):
1899- """
1900- Increment a bitfield by a given amount.
1901- :param fmt: format-string for the bitfield being updated, e.g. 'u8'
1902- for an unsigned 8-bit integer.
1903- :param offset: offset (in number of bits). If prefixed with a
1904- '#', this is an offset multiplier, e.g. given the arguments
1905- fmt='u8', offset='#2', the offset will be 16.
1906- :param int increment: value to increment the bitfield by.
1907- :param str overflow: overflow algorithm. Defaults to WRAP, but other
1908- acceptable values are SAT and FAIL. See the Redis docs for
1909- descriptions of these algorithms.
1910- :returns: a :py:class:`BitFieldOperation` instance.
1911- """
1912- if overflow is not None :
1913- self .overflow (overflow )
1914-
1915- self .operations .append (('INCRBY' , fmt , offset , increment ))
1916- return self
1917-
1918- def get (self , fmt , offset ):
1919- """
1920- Get the value of a given bitfield.
1921- :param fmt: format-string for the bitfield being read, e.g. 'u8' for
1922- an unsigned 8-bit integer.
1923- :param offset: offset (in number of bits). If prefixed with a
1924- '#', this is an offset multiplier, e.g. given the arguments
1925- fmt='u8', offset='#2', the offset will be 16.
1926- :returns: a :py:class:`BitFieldOperation` instance.
1927- """
1928- self .operations .append (('GET' , fmt , offset ))
1929- return self
1930-
1931- def set (self , fmt , offset , value ):
1932- """
1933- Set the value of a given bitfield.
1934- :param fmt: format-string for the bitfield being read, e.g. 'u8' for
1935- an unsigned 8-bit integer.
1936- :param offset: offset (in number of bits). If prefixed with a
1937- '#', this is an offset multiplier, e.g. given the arguments
1938- fmt='u8', offset='#2', the offset will be 16.
1939- :param int value: value to set at the given position.
1940- :returns: a :py:class:`BitFieldOperation` instance.
1941- """
1942- self .operations .append (('SET' , fmt , offset , value ))
1943- return self
1944-
1945- @property
1946- def command (self ):
1947- cmd = ['BITFIELD' , self .key ]
1948- for ops in self .operations :
1949- cmd .extend (ops )
1950- return cmd
1951-
1952- def execute (self ):
1953- """
1954- Execute the operation(s) in a single BITFIELD command. The return value
1955- is a list of values corresponding to each operation. If the client
1956- used to create this instance was a pipeline, the list of values
1957- will be present within the pipeline's execute.
1958- """
1959- command = self .command
1960- self .reset ()
1961- return self .client .execute_command (* command )
0 commit comments