x.create("Dinesh", 25) #to create a key with key_name,value given and with no time-to-live property x.create("Amrita", 70, 3600) #to create a key with key_name,value given and with time-to-live property value given(number of seconds) x.read("Dinesh") #it returns the value of the respective key in Jasonobject format 'key_name:value' x.read("Amrita") #it returns the value of the respective key in Jasonobject format if the TIME-TO-LIVE IS NOT EXPIRED else it returns an ERROR x.create("Dinesh", 50) #it returns an ERROR since the key_name already exists in the database x.modify("Dinesh", 55) #it replaces the initial value of the respective key with new value x.delete("Dinesh") #it deletes the respective key and its value from the database(memory is also freed) #we can access these using multiple threads like t1 = Thread(target=(create or read or delete), args=(key_name, value, timeout)) #as per the operation t1.start() t1.sleep() t2 = Thread(target=(create or read or delete), args=(key_name, value, timeout)) #as per the operation t2.start() t2.sleep() #and so on upto tn
import code as x x.create("abcdef", 25) x.create("ski", 70, 3600) #create a key with key_name x.read("abcdef") #returns the value of key_name x.read("ski") #returns the value of the respective key in Jasonobject x.create("abcdef", 50) x.modify("abcdef", 55) #replaces the initial value of the respective key with new value x.delete("abcdef") t1 = Thread(target=(create or read or delete), args=(key_name, value, timeout)) t1.start() t1.sleep() t2 = Thread(target=(create or read or delete), args=(key_name, value, timeout)) t2.start() t2.sleep()
x.create("Sulthan", 60, 3600) #to create a key with key_name,value given and with time-to-live property value given(number of seconds) x.read("Tippu") #it returns the value of the respective key in Jasonobject format 'key_name:value' x.read("Sulthan") #it returns the value of the respective key in Jasonobject format if the TIME-TO-LIVE IS NOT EXPIRED else it returns an ERROR x.create("Tippu", 75) #it returns an ERROR since the key_name already exists in the database #To overcome this error #either use modify operation to change the value of a key #or use delete operation and recreate it x.modify("Tippu", 55) #it replaces the initial value of the respective key with new value x.delete("Tippu") #it deletes the respective key and its value from the database(memory is also freed) #we can access these using multiple threads like t1 = Thread(target=(create or read or delete), args=(key_name, value, timeout)) #as per the operation t1.start() t1.sleep() t2 = Thread(target=(create or read or delete), args=(key_name, value, timeout)) #as per the operation t2.start() t2.sleep() #and so on upto tn
import code as x import threading as Thread _db_lock=Thread.Lock() x.create("rani",50) x.create("src",70,3600) x.read("rani") x.read("src") x.create("rani",70) x.modify("rani",75) x.delete("rani") t1=Thread(target=(create or read or delete),args=(key_name,value,timeout)) t1.start() t1.sleep() t2=Thread(target=(create or read or delete),args=(key_name,value,timeout)) t2.start() t2.sleep()
"has expired") #error message5 else: if key not in d: print( "error: given key does not exist in database. Please enter a valid key" ) #error message6 else: l = [] l.append(value) l.append(b[1]) d[key] = l while (1): print("choose one operation: 1.create 2.read 3.modify 4.delete") n = int(input()) if (n == 1): input1 = input("enter the key ") value = int(input("enter the vaue ")) x.create(input1, value) elif (n == 2): input2 = input("enter the key ") print(x.read(input2)) elif (n == 3): input3 = input("enter the key ") value1 = int(input("enter the value ")) x.modify(input3, value1) elif (n == 4): input4 = input("enter the key ") x.delete(input4)
x.create("src", 70, 3600) #to create a key with key_name,value given and with time-to-live property value given(number of seconds) x.read("Amrita") #it returns the value of the respective key in Jasonobject format 'key_name:value' x.read("src") #it returns the value of the respective key in Jasonobject format if the TIME-TO-LIVE IS NOT EXPIRED else it returns an ERROR x.create("Amrita", 50) #it returns an ERROR since the key_name already exists in the database #To overcome this error #either use modify operation to change the value of a key #or use delete operation and recreate it x.modify("Amrita", 55) #it replaces the initial value of the respective key with new value x.delete("Amrita") #it deletes the respective key and its value from the database(memory is also freed) #we can access these using multiple threads like t1 = Thread(target=(create or read or delete), args=(key_name, value, timeout)) #as per the operation t1.start() t1.sleep() t2 = Thread(target=(create or read or delete), args=(key_name, value, timeout)) #as per the operation t2.start() t2.sleep() #and so on upto tn
x.create("suyeb", 22) # to create a key with key_name,value given and with time-to-live property value given(number of seconds) x.read("suyeb") # it returns the value of the respective key in Jasonobject format 'key_name:value' x.read("vipin") # it returns the value of the respective key in Jasonobject format if the TIME-TO-LIVE IS NOT EXPIRED else it returns an ERROR x.create("vipin", 50) # it returns an ERROR since the key_name already exists in the database # To overcome this error # either use modify operation to change the value of a key # or use delete operation and recreate it x.modify("suyeb", 55) # it replaces the initial value of the respective key with new value x.delete("vipin") # it deletes the respective key and its value from the database(memory is also freed) # we can access these using multiple threads like x.is_empty() # checking whether file has any data or not for which "is-empty" i used. # and so on upto tn # the code also returns other errors like # "invalidkey" if key_length is greater than 32 or key_name contains any numeric,special characters etc., # "key doesnot exist" if key_name was mis-spelt or deleted earlier