@@ -12,6 +12,7 @@ describe("The 'eval' method", function () {
1212
1313 describe ( "using " + parser + " and " + ip , function ( ) {
1414 var client ;
15+ var source = "return redis.call('set', 'sha', 'test')" ;
1516
1617 beforeEach ( function ( done ) {
1718 client = redis . createClient . apply ( redis . createClient , args ) ;
@@ -94,31 +95,41 @@ describe("The 'eval' method", function () {
9495 } ) ;
9596 } ) ;
9697
98+ it ( 'allows a script to be executed that accesses the redis API without callback' , function ( done ) {
99+ helper . serverVersionAtLeast . call ( this , client , [ 2 , 5 , 0 ] ) ;
100+ client . eval ( source , 0 ) ;
101+ client . get ( 'sha' , helper . isString ( 'test' , done ) ) ;
102+ } ) ;
103+
97104 describe ( 'evalsha' , function ( ) {
98- var source = "return redis.call('get', 'sha test')" ;
99105 var sha = crypto . createHash ( 'sha1' ) . update ( source ) . digest ( 'hex' ) ;
100106
101- beforeEach ( function ( done ) {
102- client . set ( "sha test" , "eval get sha test" , function ( err , res ) {
103- return done ( err ) ;
104- } ) ;
105- } ) ;
106-
107107 it ( 'allows a script to be executed that accesses the redis API' , function ( done ) {
108108 helper . serverVersionAtLeast . call ( this , client , [ 2 , 5 , 0 ] ) ;
109- client . eval ( source , 0 , helper . isString ( 'eval get sha test' , done ) ) ;
109+ client . eval ( source , 0 , helper . isString ( 'OK' ) ) ;
110+ client . get ( 'sha' , helper . isString ( 'test' , done ) ) ;
110111 } ) ;
111112
112113 it ( 'can execute a script if the SHA exists' , function ( done ) {
113114 helper . serverVersionAtLeast . call ( this , client , [ 2 , 5 , 0 ] ) ;
114- client . evalsha ( sha , 0 , helper . isString ( 'eval get sha test' , done ) ) ;
115+ client . evalsha ( sha , 0 , helper . isString ( 'OK' ) ) ;
116+ client . get ( 'sha' , helper . isString ( 'test' , done ) ) ;
115117 } ) ;
116118
117119 it ( 'returns an error if SHA does not exist' , function ( done ) {
118120 helper . serverVersionAtLeast . call ( this , client , [ 2 , 5 , 0 ] ) ;
119121 client . evalsha ( 'ffffffffffffffffffffffffffffffffffffffff' , 0 , helper . isError ( done ) ) ;
120122 } ) ;
121123
124+ it ( 'emit an error if SHA does not exist without any callback' , function ( done ) {
125+ helper . serverVersionAtLeast . call ( this , client , [ 2 , 5 , 0 ] ) ;
126+ client . evalsha ( 'ffffffffffffffffffffffffffffffffffffffff' , 0 ) ;
127+ client . on ( 'error' , function ( err ) {
128+ assert ( / N O S C R I P T N o m a t c h i n g s c r i p t . P l e a s e u s e E V A L ./ . test ( err . message ) ) ;
129+ done ( ) ;
130+ } ) ;
131+ } ) ;
132+
122133 it ( 'emits an error if SHA does not exist and no callback has been provided' , function ( done ) {
123134 client . on ( 'error' , function ( err ) {
124135 assert . equal ( err . message , 'NOSCRIPT No matching script. Please use EVAL.' ) ;
0 commit comments