Object inspects the internals of Redis Objects
(ctx *Context, txn *db.Transaction)
| 195 | |
| 196 | // Object inspects the internals of Redis Objects |
| 197 | func Object(ctx *Context, txn *db.Transaction) (OnCommit, error) { |
| 198 | argc := len(ctx.Args) |
| 199 | subCmd := strings.ToLower(ctx.Args[0]) |
| 200 | cmdErr := fmt.Errorf("ERR Unknown subcommand or wrong number of arguments for '%s'. Try OBJECT help", subCmd) |
| 201 | if argc == 1 && subCmd == "help" { |
| 202 | |
| 203 | helpInfo := [][]byte{ |
| 204 | []byte("OBJECT <subcommand> key. Subcommands:"), |
| 205 | []byte("ENCODING <key> -- Return the kind of internal representation used in order to store the value associated with a key."), |
| 206 | []byte("FREQ <key> -- Return the access frequency index of the key. The returned integer is proportional to the logarithm of the recent access frequency of the key."), |
| 207 | []byte("IDLETIME <key> -- Return the idle time of the key, that is the approximated number of seconds elapsed since the last access to the key."), |
| 208 | []byte("REFCOUNT <key> -- Return the number of references of the value associated with the specified key."), |
| 209 | } |
| 210 | return BytesArray(ctx.Out, helpInfo), nil |
| 211 | } else if argc == 2 { |
| 212 | key := []byte(ctx.Args[1]) |
| 213 | obj, err := txn.Object(key) |
| 214 | if err != nil { |
| 215 | if err == db.ErrKeyNotFound { |
| 216 | return NullBulkString(ctx.Out), nil |
| 217 | } |
| 218 | return nil, errors.New("ERR " + err.Error()) |
| 219 | } |
| 220 | switch subCmd { |
| 221 | case "refcount", "freq": |
| 222 | return Integer(ctx.Out, 0), nil |
| 223 | case "idletime": |
| 224 | sec := int64(time.Since(time.Unix(0, obj.UpdatedAt)).Seconds()) |
| 225 | return Integer(ctx.Out, sec), nil |
| 226 | case "encoding": |
| 227 | return SimpleString(ctx.Out, obj.Encoding.String()), nil |
| 228 | } |
| 229 | } |
| 230 | return nil, cmdErr |
| 231 | } |
| 232 | |
| 233 | // Type returns the string representation of the type of the value stored at key |
| 234 | func Type(ctx *Context, txn *db.Transaction) (OnCommit, error) { |
nothing calls this directly
no test coverage detected