File tree 2 files changed +33
-0
lines changed
2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -112,4 +112,29 @@ describe("Read Your Writes Feature", () => {
112
112
const updatedSync = redis . client . upstashSyncToken ;
113
113
expect ( updatedSync ) . not . toEqual ( initialSync ) ;
114
114
} ) ;
115
+
116
+ test ( "should updat read your writes sync token using set/get" , async ( ) => {
117
+ const redis = new PublicRedis ( {
118
+ url : process . env . UPSTASH_REDIS_REST_URL ,
119
+ token : process . env . UPSTASH_REDIS_REST_TOKEN ,
120
+ } ) ;
121
+
122
+ // should change from "" to string
123
+ expect ( redis . readYourWritesSyncToken ) . toBe ( "" ) ;
124
+ await redis . set ( "key" , "value" ) ;
125
+ expect ( redis . readYourWritesSyncToken ) . not . toBe ( "" ) ;
126
+ expect ( typeof redis . readYourWritesSyncToken ) . toBe ( "string" ) ;
127
+
128
+ // should change after set
129
+ const syncToken = redis . readYourWritesSyncToken ;
130
+ await redis . set ( "key" , "value" ) ;
131
+ expect ( syncToken ) . not . toBe ( redis . readYourWritesSyncToken ) ;
132
+
133
+ // should be able to set
134
+ const newSyncToken = "my-new-sync-token" ;
135
+ redis . readYourWritesSyncToken = newSyncToken ;
136
+ expect ( redis . readYourWritesSyncToken ) . toBe ( newSyncToken ) ;
137
+
138
+ await redis . set ( "key" , "value" ) ;
139
+ } ) ;
115
140
} ) ;
Original file line number Diff line number Diff line change @@ -217,6 +217,14 @@ export class Redis {
217
217
this . enableAutoPipelining = opts ?. enableAutoPipelining ?? true ;
218
218
}
219
219
220
+ get readYourWritesSyncToken ( ) : string | undefined {
221
+ return this . client . upstashSyncToken ;
222
+ }
223
+
224
+ set readYourWritesSyncToken ( session : string | undefined ) {
225
+ this . client . upstashSyncToken = session ;
226
+ }
227
+
220
228
get json ( ) {
221
229
return {
222
230
/**
You can’t perform that action at this time.
0 commit comments