@@ -2527,6 +2527,123 @@ export function runBaseTests<Context>(config: {
25272527 } ,
25282528 config . timeout ,
25292529 ) ;
2530+
2531+ async function classicSet ( client : BaseClient , key : string , value : string ) {
2532+ const setRes = await client . set ( key , value ) ;
2533+ expect ( setRes ) . toEqual ( "OK" ) ;
2534+ const getRes = await client . get ( key ) ;
2535+ expect ( getRes ) . toEqual ( value ) ;
2536+ }
2537+
2538+ async function setWithExpiryOptions (
2539+ client : BaseClient ,
2540+ key : string ,
2541+ value : string ,
2542+ ) {
2543+ const setRes = await client . set ( key , value , {
2544+ expiry : {
2545+ type : "milliseconds" ,
2546+ count : 500 ,
2547+ } ,
2548+ } ) ;
2549+ expect ( setRes ) . toEqual ( "OK" ) ;
2550+ const getRes = await client . get ( key ) ;
2551+ expect ( getRes ) . toEqual ( value ) ;
2552+
2553+ const setRes2 = await client . set ( key , value , {
2554+ expiry : {
2555+ type : "seconds" ,
2556+ count : 1 ,
2557+ } ,
2558+ } ) ;
2559+ expect ( setRes2 ) . toEqual ( "OK" ) ;
2560+ const getRes2 = await client . get ( key ) ;
2561+ expect ( getRes2 ) . toEqual ( value ) ;
2562+
2563+ const setRes3 = await client . set ( key , value , {
2564+ expiry : "keepExisting" ,
2565+ } ) ;
2566+ expect ( setRes3 ) . toEqual ( "OK" ) ;
2567+ const getRes3 = await client . get ( key ) ;
2568+ expect ( getRes3 ) . toEqual ( value ) ;
2569+
2570+ const setRes4 = await client . set ( key , value , {
2571+ expiry : {
2572+ type : "unixMilliseconds" ,
2573+ count : 2 ,
2574+ } ,
2575+ } ) ;
2576+ expect ( setRes4 ) . toEqual ( "OK" ) ;
2577+ setTimeout ( ( ) => { } , 5 ) ;
2578+ const getRes4 = await client . get ( key ) ;
2579+ expect ( getRes4 ) . toEqual ( null ) ;
2580+ }
2581+
2582+ async function setWithExistOptions (
2583+ client : BaseClient ,
2584+ key : string ,
2585+ value : string ,
2586+ ) {
2587+ const setRes = await client . set ( key , value , {
2588+ conditionalSet : "onlyIfExists" ,
2589+ } ) ;
2590+ expect ( setRes ) . toEqual ( "OK" ) ;
2591+ const getRes = await client . get ( key ) ;
2592+ expect ( getRes ) . toEqual ( value ) ;
2593+
2594+ const setRes2 = await client . set ( key , value , {
2595+ conditionalSet : "onlyIfDoesNotExist" ,
2596+ } ) ;
2597+ expect ( setRes2 ) . toEqual ( null ) ;
2598+ const getRes2 = await client . get ( key ) ;
2599+ expect ( getRes2 ) . toEqual ( value ) ;
2600+ }
2601+
2602+ async function setWithGetOldOptions (
2603+ client : BaseClient ,
2604+ key : string ,
2605+ value : string ,
2606+ ) {
2607+ const setRes = await client . set ( key , value , {
2608+ returnOldValue : true ,
2609+ } ) ;
2610+ expect ( setRes ) . toEqual ( value ) ;
2611+ const getRes = await client . get ( key ) ;
2612+ expect ( getRes ) . toEqual ( value ) ;
2613+ const setRes2 = await client . set ( key + "1" , value , {
2614+ returnOldValue : true ,
2615+ } ) ;
2616+ expect ( setRes2 ) . toEqual ( null ) ;
2617+ const getRes2 = await client . get ( key + "1" ) ;
2618+ expect ( getRes2 ) . toEqual ( value ) ;
2619+ }
2620+
2621+ it . each ( [ ProtocolVersion . RESP2 , ProtocolVersion . RESP3 ] ) (
2622+ "Set commands with options test_%p" ,
2623+ async ( protocol ) => {
2624+ await runTest ( async ( client : BaseClient ) => {
2625+ const key = uuidv4 ( ) ;
2626+ const value = uuidv4 ( ) ;
2627+ await classicSet ( client , key , value ) ;
2628+ await setWithExpiryOptions ( client , key , value ) ;
2629+ await setWithExistOptions ( client , key , value ) ;
2630+ await setWithGetOldOptions ( client , key , value ) ;
2631+ // try to set with all options
2632+ const setRes = await client . set ( key + "1" , value + "1" , {
2633+ expiry : {
2634+ type : "seconds" ,
2635+ count : 1 ,
2636+ } ,
2637+ conditionalSet : "onlyIfExists" ,
2638+ returnOldValue : true ,
2639+ } ) ;
2640+ expect ( setRes ) . toEqual ( value ) ;
2641+ const getRes = await client . get ( key ) ;
2642+ expect ( getRes ) . toEqual ( value + "1" ) ;
2643+ } , protocol ) ;
2644+ } ,
2645+ config . timeout ,
2646+ ) ;
25302647}
25312648
25322649export function runCommonTests < Context > ( config : {
0 commit comments