Skip to content

slowlog_get() return value count less than Redis Doc mentioned and redis-cli returned. #2677

Closed
@gzOne2Free

Description

@gzOne2Free

Thanks for wanting to report an issue you've found in redis-py. Please delete this text and fill in the template below.
It is of course not always possible to reduce your code to a small test case, but it's highly appreciated to have as much data as possible. Thank you!

Version: What redis-py and what redis version is the issue happening on?

redis-py version: 4.5.3 (and 4.5.1 before I upgrade version that try to solve the problem)
redis version: Redis server v=7.0.8 sha=00000000:0 malloc=jemalloc-5.2.1 bits=64 build=12b7d21b977d6ccd

Platform: What platform / version? (For example Python 3.5.1 on Windows 7 / Ubuntu 15.10 / Azure)

Platform: Python 3.8.10 on Ubuntu 20.04-05 TLS

Description: Description of your issue, stack traces from errors and code that reproduces the issue
As Redis doc mentioned, 'slowlog get' command will return 6 values for each item:

Each entry from the slow log is comprised of the following six values:

1. A unique progressive identifier for every slow log entry.
2. The unix timestamp at which the logged command was processed.
3. The amount of time needed for its execution, in microseconds.
4. The array composing the arguments of the command.
5. Client IP address and port.
6. Client name if set via the [CLIENT SETNAME](https://redis.io/commands/client-setname) command.

Doc URL: https://redis.io/commands/slowlog-get/

Here is my redis-cli output sample:

1) 1) (integer) 19
   2) (integer) 1680064492
   3) (integer) 10187
   4) 1) "LRANGE"
      2) "mylist:{8M}}"
      3) "0"
      4) "599"
   5) "192.168.8.1:48132"
   6) ""

And this is redis-py output sample:

[{'id': 673, 'start_time': 1680018547, 'duration': 17716, 'command': b'CLUSTER NODES'}]

I have try both execute_command() and slowlog_get() to get result, but no luck.
My code snippet:

    def get_slowlog(self, num=None):
        redis_command='SLOWLOG GET'
        try:
            # result = self.r.execute_command(redis_command)
            if num:
                result = self.r.slowlog_get(num=num)
            else:
                result = self.r.slowlog_get()

Remark: where 'r' in the code is Redis client:

                self.r = Redis(
                    host=host, 
                    port=port, 
                    db=0, 
                    password=self.PASSWORD, 
                    retry=self.RETRY, 
                    # retry_on_error=self.RETRY_ON_ERROR, 
                    socket_timeout=60, 
                    socket_connect_timeout=10
                    )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions