@@ -823,118 +823,6 @@ def test_clear(self, cache: RedisCache):
823823 value_from_cache_after_clear = cache .get ("foo" )
824824 assert value_from_cache_after_clear is None
825825
826- def test_hset (self , cache : RedisCache ):
827- if isinstance (cache .client , ShardClient ):
828- pytest .skip ("ShardClient doesn't support get_client" )
829- cache .hset ("foo_hash1" , "foo1" , "bar1" )
830- cache .hset ("foo_hash1" , "foo2" , "bar2" )
831- assert cache .hlen ("foo_hash1" ) == 2
832- assert cache .hexists ("foo_hash1" , "foo1" )
833- assert cache .hexists ("foo_hash1" , "foo2" )
834-
835- def test_hdel (self , cache : RedisCache ):
836- if isinstance (cache .client , ShardClient ):
837- pytest .skip ("ShardClient doesn't support get_client" )
838- cache .hset ("foo_hash2" , "foo1" , "bar1" )
839- cache .hset ("foo_hash2" , "foo2" , "bar2" )
840- assert cache .hlen ("foo_hash2" ) == 2
841- deleted_count = cache .hdel ("foo_hash2" , "foo1" )
842- assert deleted_count == 1
843- assert cache .hlen ("foo_hash2" ) == 1
844- assert not cache .hexists ("foo_hash2" , "foo1" )
845- assert cache .hexists ("foo_hash2" , "foo2" )
846-
847- def test_hlen (self , cache : RedisCache ):
848- if isinstance (cache .client , ShardClient ):
849- pytest .skip ("ShardClient doesn't support get_client" )
850- assert cache .hlen ("foo_hash3" ) == 0
851- cache .hset ("foo_hash3" , "foo1" , "bar1" )
852- assert cache .hlen ("foo_hash3" ) == 1
853- cache .hset ("foo_hash3" , "foo2" , "bar2" )
854- assert cache .hlen ("foo_hash3" ) == 2
855-
856- def test_hkeys (self , cache : RedisCache ):
857- if isinstance (cache .client , ShardClient ):
858- pytest .skip ("ShardClient doesn't support get_client" )
859- cache .hset ("foo_hash4" , "foo1" , "bar1" )
860- cache .hset ("foo_hash4" , "foo2" , "bar2" )
861- cache .hset ("foo_hash4" , "foo3" , "bar3" )
862- keys = cache .hkeys ("foo_hash4" )
863- assert len (keys ) == 3
864- for i in range (len (keys )):
865- assert keys [i ] == f"foo{ i + 1 } "
866-
867- def test_hexists (self , cache : RedisCache ):
868- if isinstance (cache .client , ShardClient ):
869- pytest .skip ("ShardClient doesn't support get_client" )
870- cache .hset ("foo_hash5" , "foo1" , "bar1" )
871- assert cache .hexists ("foo_hash5" , "foo1" )
872- assert not cache .hexists ("foo_hash5" , "foo" )
873-
874- def test_hash_version_support (self , cache : RedisCache ):
875- """Test that version parameter works correctly for hash methods."""
876- if isinstance (cache .client , ShardClient ):
877- pytest .skip ("ShardClient doesn't support get_client" )
878-
879- # Set values with different versions
880- cache .hset ("my_hash" , "field1" , "value1" , version = 1 )
881- cache .hset ("my_hash" , "field2" , "value2" , version = 1 )
882- cache .hset ("my_hash" , "field1" , "different_value" , version = 2 )
883-
884- # Verify both versions exist independently
885- assert cache .hexists ("my_hash" , "field1" , version = 1 )
886- assert cache .hexists ("my_hash" , "field2" , version = 1 )
887- assert cache .hexists ("my_hash" , "field1" , version = 2 )
888- assert not cache .hexists ("my_hash" , "field2" , version = 2 )
889-
890- # Verify hlen works with versions
891- assert cache .hlen ("my_hash" , version = 1 ) == 2
892- assert cache .hlen ("my_hash" , version = 2 ) == 1
893-
894- # Verify hkeys works with versions
895- keys_v1 = cache .hkeys ("my_hash" , version = 1 )
896- assert len (keys_v1 ) == 2
897- assert "field1" in keys_v1
898- assert "field2" in keys_v1
899-
900- keys_v2 = cache .hkeys ("my_hash" , version = 2 )
901- assert len (keys_v2 ) == 1
902- assert "field1" in keys_v2
903-
904- # Verify hdel works with versions
905- cache .hdel ("my_hash" , "field1" , version = 1 )
906- assert not cache .hexists ("my_hash" , "field1" , version = 1 )
907- assert cache .hexists ("my_hash" , "field1" , version = 2 ) # v2 should still exist
908-
909- def test_hash_key_structure_in_redis (self , cache : RedisCache ):
910- """Test that hash keys are prefixed but fields are not."""
911- if isinstance (cache .client , ShardClient ):
912- pytest .skip ("ShardClient doesn't support get_client" )
913-
914- # Get raw Redis client
915- client = cache .client .get_client (write = False )
916-
917- # Set some hash data
918- cache .hset ("user:1000" , "email" , "alice@example.com" , version = 2 )
919- cache .hset ("user:1000" , "name" , "Alice" , version = 2 )
920-
921- # Get the actual Redis key that was created
922- expected_key = cache .client .make_key ("user:1000" , version = 2 )
923-
924- # Verify the hash exists in Redis with the prefixed key
925- assert client .exists (expected_key )
926- assert client .type (expected_key ) == b"hash"
927-
928- # Verify fields are stored WITHOUT prefix
929- actual_fields = client .hkeys (expected_key )
930- # Fields should be plain "email" and "name", not prefixed
931- assert b"email" in actual_fields
932- assert b"name" in actual_fields
933-
934- # Verify field values are correct
935- assert client .hget (expected_key , b"email" ) is not None
936- assert client .hget (expected_key , b"name" ) is not None
937-
938826 def test_sadd (self , cache : RedisCache ):
939827 assert cache .sadd ("foo" , "bar" ) == 1
940828 assert cache .smembers ("foo" ) == {"bar" }
0 commit comments