@@ -17,8 +17,15 @@ async def do_snaphots_for_keyspace(cls):
1717 True if the snapshot operation was successful. Class 'str' if the snapshot operation failed.
1818 """
1919
20+ if cls .persistent :
21+ raise ValueError ("Snapshots can only be set for in-memory keyspaces." )
22+
2023 query = orjson .dumps ({
21- "raw" : ["do-snapshots-for-keyspace" , "store" , cls .store , "keyspace" , cls .keyspace , "persistent" , "n" ],
24+ "raw" : [
25+ "do-snapshots-for-keyspace" ,
26+ "store" , cls .store ,
27+ "keyspace" , cls .keyspace ,
28+ ],
2229 "credentials" : [cls .username , cls .password ]
2330 })
2431
@@ -31,8 +38,15 @@ async def clean_snapshots_for_keyspace(cls):
3138 True if the snapshot operation was successful. Class 'str' if the snapshot operation failed.
3239 """
3340
41+ if cls .persistent :
42+ raise ValueError ("Snapshots can only be set for in-memory keyspaces." )
43+
3444 query = orjson .dumps ({
35- "raw" : ["clean-snapshots-for-keyspace" , "store" , cls .store , "keyspace" , cls .keyspace , "persistent" , "n" ],
45+ "raw" : [
46+ "clean-snapshots-for-keyspace" ,
47+ "store" , cls .store ,
48+ "keyspace" , cls .keyspace ,
49+ ],
3650 "credentials" : [cls .username , cls .password ]
3751 })
3852
@@ -45,8 +59,15 @@ async def stop_snapshots_for_keyspace(cls):
4559 True if the snapshot operation was successful. Class 'str' if the snapshot operation failed.
4660 """
4761
62+ if cls .persistent :
63+ raise ValueError ("Snapshots can only be set for in-memory keyspaces." )
64+
4865 query = orjson .dumps ({
49- "raw" : ["stop-snapshots-for-keyspace" , "store" , cls .store , "keyspace" , cls .keyspace , "persistent" , "n" ],
66+ "raw" : [
67+ "stop-snapshots-for-keyspace" ,
68+ "store" , cls .store ,
69+ "keyspace" , cls .keyspace ,
70+ ],
5071 "credentials" : [cls .username , cls .password ]
5172 })
5273
@@ -72,7 +93,7 @@ async def insert_custom_key(cls, custom_key: str, expire_sec: int = 0):
7293
7394 @classmethod
7495 async def insert_custom_key_value (cls , custom_key : str , value : dict , expire_sec : int = 0 ):
75- """
96+ """
7697 Args:
7798 custom_key: A custom key to insert into the store. This key can be used to retrieve the value later.
7899 value: A Python class / dict to insert into the store.
@@ -91,10 +112,10 @@ async def insert_custom_key_value(cls, custom_key: str, value: dict, expire_sec:
91112
92113 query = convert_to_binary_query (cls , key = custom_key_converted , value = value , expire_sec = expire_sec )
93114 return await cls ._run_query (query )
94-
115+
95116 @classmethod
96117 async def insert_value (cls , value : dict , expire_sec : int = 0 ):
97- """
118+ """
98119 Args:
99120 value: A Python class / dict to insert into the store.
100121 expire_sec: The number of seconds before the inserted value expires.
@@ -103,23 +124,23 @@ async def insert_value(cls, value: dict, expire_sec: int = 0):
103124 """
104125 if not value :
105126 raise ValueError ("No value provided for insertion." )
106-
127+
107128 cls .command = "insert_value"
108129
109130 query = convert_to_binary_query (cls , value = value , expire_sec = expire_sec )
110131 return await cls ._run_query (query )
111-
132+
112133 @classmethod
113134 async def update_value (cls , key : Union [str , None ] = None , custom_key : Union [str , None ] = None , expire_sec : int = 0 , ** filters ):
114135 """
115136 Update the value associated with a given key in the store. If a custom key is provided,
116137 it will be converted to the appropriate format before updating.
117138
118139 Args:
119- key (int | str, optional): The key whose associated value needs to be updated.
140+ key (int | str, optional): The key whose associated value needs to be updated.
120141 This can either be an integer or a string. Default is an empty string,
121142 which will be ignored if custom_key is provided.
122- custom_key (str, optional): The custom key whose associated value needs to be updated.
143+ custom_key (str, optional): The custom key whose associated value needs to be updated.
123144 Default is an empty string.
124145 filters (dict): A dictionary of field-value pairs that need to be updated in the store.
125146
@@ -135,36 +156,36 @@ async def update_value(cls, key: Union[str, None] = None, custom_key: Union[str,
135156 raise ValueError ("No filters provided" )
136157 if not key :
137158 raise ValueError ("No key provided" )
138-
159+
139160 cls .command = "update_value"
140161
141162 query = convert_to_binary_query (cls , key = key , value = filters , expire_sec = expire_sec ) # Convert the key and filters into a binary query format
142163 return await cls ._run_query (query ) # Run the query and return the result
143164
144165 @classmethod
145166 async def insert_bulk (cls , bulk_values : list , expire_sec : int = 0 ):
146- """
167+ """
147168 Args:
148169 bulk_values: A list of Python objects to insert into the store.
149170 expire_sec: The number of seconds before the inserted values expire.
150-
171+
151172 Returns:
152173 True if the bulk insert operation was successful.
153174 List of values that were not inserted.
154175 """
155176
156177 if not bulk_values :
157178 raise ValueError ("No values provided for bulk insertion." )
158-
179+
159180 cls .command = "insert_bulk"
160181 query = convert_to_binary_query (cls , bulk_values = bulk_values , expire_sec = expire_sec )
161182 return await cls ._run_query (query )
162-
183+
163184 @classmethod
164185 async def get_keys (cls ):
165186 """
166187 Get all keys in the store.
167-
188+
168189 Returns:
169190 A list of keys in the store. Class 'str' if the get operation failed.
170191 """
@@ -173,11 +194,17 @@ async def get_keys(cls):
173194 query = convert_to_binary_query (cls )
174195 return await cls ._run_query (query )
175196
176- @classmethod
197+ @classmethod
177198 async def create_keyspace (cls ):
178199
179200 query = orjson .dumps ({
180- "raw" : ["create-keyspace" , "store" , cls .store , "keyspace" , cls .keyspace , "persistent" , "y" if cls .persistent else "n" ],
201+ "raw" : [
202+ "create-keyspace" ,
203+ "store" , cls .store ,
204+ "keyspace" , cls .keyspace ,
205+ "persistent" , "y" if cls .persistent else "n" ,
206+ "distributed" , "y" if cls .distributed else "n"
207+ ],
181208 "credentials" : [cls .username , cls .password ]
182209 })
183210
0 commit comments