(m uhaha.Machine, args []string)
| 842 | return nil, uhaha.ErrWrongNumArgs |
| 843 | } |
| 844 | |
| 845 | // Retrieve the value associated with the key |
| 846 | val, err := ldb.Get([]byte(args[1])) |
| 847 | if err != nil { |
| 848 | return nil, err |
| 849 | } |
| 850 | |
| 851 | // If val is nil, the key does not exist |
| 852 | if val == nil { |
| 853 | return nil, nil |
| 854 | } |
| 855 | |
| 856 | // Return the value if the key exists |
| 857 | return val, nil |
| 858 | } |
| 859 | |
| 860 | // This is different from the RESP standard. For the sake of transaction consistency, there is no key existence judgment. |
| 861 | func cmdDEL(m uhaha.Machine, args []string) (interface{}, error) { |
| 862 | // Check if the number of arguments is correct |
| 863 | if len(args) < 2 { |
| 864 | return nil, uhaha.ErrWrongNumArgs |
| 865 | } |
| 866 | |
| 867 | // Convert the keys from string to byte slices |
| 868 | keys := make([][]byte, len(args)-1) |
| 869 | for i := 1; i < len(args); i++ { |
| 870 | keys[i-1] = []byte(args[i]) |
| 871 | } |
| 872 | |
| 873 | // Delete the keys and get the number of keys that were actually deleted |
| 874 | n, err := ldb.Del(keys...) |
| 875 | if err != nil { |
| 876 | return nil, err |
| 877 | } |
| 878 | |
| 879 | // Return the number of keys that were deleted |
nothing calls this directly
no outgoing calls
no test coverage detected